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
33
|
# File 'lib/uploadcare/rails/action_view/form_builder.rb', line 8
def uploadcare_file_field(method, ctx_name: nil, solution: "regular", **options)
unless options.key?(:multiple)
model = object&.class || object_name.to_s.camelize.safe_constantize
if model
checker = "has_uploadcare_files_for_#{method}?"
options[:multiple] = true if model.respond_to?(checker) && model.public_send(checker)
end
end
ctx_name ||= SecureRandom.uuid
field_name = "#{object_name}[#{method}]"
options[:value] = object.public_send(method) if !options.key?(:value) && object&.respond_to?(method)
field_html = @template.uploadcare_file_field_tag(
field_name,
ctx_name: ctx_name,
solution: solution,
**options
)
if object && uploadcare_object_has_errors?(method)
uploadcare_error_wrapping(field_html)
else
field_html
end
end
|