Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Defined in:
- lib/uploadcare/rails/action_view/uploadcare_form_builder.rb
Instance Method Summary collapse
-
#uploadcare_file(method, ctx_name: nil, solution: "regular", **options) ⇒ ActiveSupport::SafeBuffer
Generates an Uploadcare File Uploader field bound to the form’s model.
Instance Method Details
#uploadcare_file(method, ctx_name: nil, solution: "regular", **options) ⇒ ActiveSupport::SafeBuffer
Generates an Uploadcare File Uploader field bound to the form’s model. Automatically handles validation error wrapping.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/uploadcare/rails/action_view/uploadcare_form_builder.rb', line 37 def uploadcare_file(method, ctx_name: nil, solution: "regular", **) # Auto-detect multiple from mount_uploadcare_file_group unless explicitly set unless .key?(:multiple) model = object_name.to_s.camelize.safe_constantize if model checker = "has_uploadcare_file_group_for_#{method}?" [:multiple] = true if model.respond_to?(checker) && model.public_send(checker) end end ctx_name ||= SecureRandom.uuid field_name = "#{object_name}[#{method}]" # Generate the uploader field using the template's helper field_html = @template.uploadcare_uploader_field_tag( field_name, ctx_name: ctx_name, solution: solution, ** ) # Apply error wrapping if object has validation errors on this method if object && uploadcare_object_has_errors?(method) uploadcare_error_wrapping(field_html) else field_html end end |