Module: Anaconda::UploadHelper

Defined in:
lib/anaconda/upload_helper.rb

Overview

Defined Under Namespace

Classes: S3Uploader

Instance Method Summary collapse

Instance Method Details

#anaconda_uploader_form(options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/anaconda/upload_helper.rb', line 14

def anaconda_uploader_form(options = {}, &block)
  uploader = S3Uploader.new(options)
  form_tag(uploader.url, uploader.form_options) do
    uploader.fields.map do |name, value|
      hidden_field_tag(name, value)
    end.join.html_safe + file_field_tag("file").html_safe# + capture(&block)
  end
end

#anaconda_uploader_form_for(instance, attribute, form_options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/anaconda/upload_helper.rb', line 4

def anaconda_uploader_form_for(instance, attribute, form_options = {})
  a_class = instance.class unless instance.kind_of? Class
  if a_class.anaconda_options[attribute].present
    options = a_class.anaconda_options[attribute].dup
  else
    raise AnacondaError, "attribute options not set for column #{attribute}. Did you add `anaconda_for :#{attribute}` to the model?"
  end
  options[:base_key] = instance.send(options[:base_key].to_s) if options[:base_key].kind_of? Symbol
  render(:template =>"anaconda/_uploader_form_for.html.haml", :locals => {resource: instance, options: options.merge(as: attribute, form_options: form_options)}, layout: false).to_s
end