Class: Bard::FileField::Field

Inherits:
ActionView::Helpers::Tags::TextField
  • Object
show all
Defined in:
lib/bard/file_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/file_field/field.rb', line 4

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

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