Module: ActionView::Helpers::FormTagHelper

Defined in:
lib/acts_as_assets/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_instances(model, methods) ⇒ Object



43
44
45
# File 'lib/acts_as_assets/form_helper.rb', line 43

def asset_instances(model, methods)
  Array(methods).inject(model) { |object, method| object.send(method) }
end

#asset_multiple_upload_tag(model, methods, *args) ⇒ Object



18
19
20
21
22
23
# File 'lib/acts_as_assets/form_helper.rb', line 18

def asset_multiple_upload_tag(model, methods, *args)
  options = args.extract_options!
  type = nil
  type = args.first if args.size == 2
  asset_upload_helper(model, methods, type, "acts_as_assets/assets/asset_multiple_upload", options)
end

#asset_upload_helper(model, methods, type, partial, options) ⇒ Object

methods can be a sym that will be the method name and it will be called against the model passed or can an array of symbols and will be chained in a method call for instance asset_upload_tag(@pratica, [:back_office, :allegati], …) will call @pratica.back_office.allegati



37
38
39
40
41
# File 'lib/acts_as_assets/form_helper.rb', line 37

def asset_upload_helper(model, methods, type, partial, options)
  type ||= get_type_from_association(model, methods)
  render partial: partial,
         locals: {:@type => type, model: model, assets: asset_instances(model, methods), read_only: options[:read_only]}
end

#asset_upload_tag(model, methods, *args) ⇒ Object



25
26
27
28
29
30
# File 'lib/acts_as_assets/form_helper.rb', line 25

def asset_upload_tag(model, methods, *args)
  options = args.extract_options!
  type = nil
  type = args.first if args.size == 2
  asset_upload_helper(model, methods, type, "acts_as_assets/assets/asset_upload", options)
end

#get_type_from_association(model, methods) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/acts_as_assets/form_helper.rb', line 47

def get_type_from_association(model, methods)
  meths = Array(methods).dup

  association_name = meths.pop

  unless meths.empty?
    model = asset_instances(model, meths)
  end

  model.association(association_name).klass.to_s.underscore
end