Module: ActionView::Helpers::FormHelper

Defined in:
lib/image_thread/patches/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#image_thread_field(object_name, method, options = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/image_thread/patches/form_helper.rb', line 4

def image_thread_field(object_name, method, options = nil)
  tag     = ActionView::Helpers::Tags::Base.new(object_name, [method, 'images'].join('_'), self)
  thread  = options.delete(:thread)

  options.update(class: 'image_thread_fileupload')
  options.update(data: { url:      '/image_thread/images',
                         uploader: [object_name, method, 'uploader', SecureRandom.hex(16)].join('_'),
                         thread:   thread.to_i,
                         dir:      options[:dir],
                         name:     tag.send(:tag_name, true) })

  template = <<-HTML
    <div class="uploader-container">
      <span class="btn btn-success fileinput-button">
        <span class="glyphicon glyphicon-plus"> Add files</span>
        #{file_field_tag(:source, options)}
      </span>
      <div class="files uploader-#{method} clearfix">#{render_image_thread(thread, tag.send(:tag_name, true))}</div>
    </div>
  HTML

  template.html_safe
end