Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/filemagic/engine.rb

Instance Method Summary collapse

Instance Method Details

#filemagic_field(attribute_name, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/filemagic/engine.rb', line 53

def filemagic_field(attribute_name, options={})
  image_size = options[:image_size] || {}
  preview_size = options[:preview_size] || {}
  preview_url = Refile.attachment_url(@object, attribute_name) || ''

  is_file_field = options[:is_file_field] || false

  actions = options[:actions] || false

  input_html_options = options[:input_html] || false

  custom_attribute_name = input_html_options ?  input_html_options[:name] : false

  data_attributes = {
    component: 'Uploader',
    object: object_name,
    attribute: attribute_name,
    custom_attribute_name: custom_attribute_name,
    offset_y: options[:offset_y] || false,
    image_size: image_size,
    preview_size: preview_size,
    preview_url: preview_url,
    as: "file",
    url: "/attachments/cache",
    fields: {},
    is_file_field: is_file_field,
    actions: actions
    }

  data_attributes = data_attributes.merge(Refile.cache.presign.as_json) if Refile.cache.class.method_defined?(:presign)

  @template.(:div, nil, { class: 'fm-uploader-wrapper', data: data_attributes})
end