Class: Bard::AttachmentField::Field

Inherits:
ActionView::Helpers::Tags::TextField
  • Object
show all
Defined in:
lib/bard/attachment_field/field.rb

Instance Method Summary collapse

Instance Method Details

#render(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bard/attachment_field/field.rb', line 4

def render &block
  options = @options.transform_keys { _1.to_s.dasherize }.reverse_merge({
    "directupload" => "/rails/active_storage/direct_uploads",
    "preview" => true,
  })
  add_default_name_and_id(options)

  ("input-attachment", options) do
    next block.call(options) if block
    Array(object.try(@method_name)).map do |attachment|
      ("attachment-file", nil, {
        name: options["name"],
        src: blob_path(attachment),
        filename: attachment.filename,
        value: attachment.signed_id,
        preview: options["preview"],
      })
    end.join("\n").html_safe
  end
end