2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/inputs/image_file_input.rb', line 2
def input(wrapper_options = nil)
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
container_id = "image-upload-#{SecureRandom.hex(8)}"
file_input = @builder.file_field(attribute_name, merged_input_options.merge(
id: container_id,
class: 'form-control image-file-input',
data: {
preview_id: "#{container_id}-preview",
max_size: options[:max_file_size] || 10.megabytes
}
))
preview_container = template.tag.div('',
id: "#{container_id}-preview",
class: 'image-preview-container mt-2',
style: 'display: none;')
template.tag.div(
file_input + preview_container,
class: 'image-upload-wrapper',
data: {
controller: 'image-preview'
}
)
end
|