Module: Anaconda::UploadHelper
- Defined in:
- lib/anaconda/upload_helper.rb
Overview
Greatly inspired by railscasts.com/episodes/383-uploading-to-amazon-s3
Defined Under Namespace
Classes: S3Uploader
Instance Method Summary collapse
- #anaconda_uploader_form(options = {}, &block) ⇒ Object
- #anaconda_uploader_form_for(instance, attribute, form_options = {}) ⇒ Object
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( = {}, &block) uploader = S3Uploader.new() form_tag(uploader.url, uploader.) 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, = {}) a_class = instance.class unless instance.kind_of? Class if a_class.[attribute].present = a_class.[attribute].dup else raise AnacondaError, "attribute options not set for column #{attribute}. Did you add `anaconda_for :#{attribute}` to the model?" end [:base_key] = instance.send([:base_key].to_s) if [:base_key].kind_of? Symbol render(:template =>"anaconda/_uploader_form_for.html.haml", :locals => {resource: instance, options: .merge(as: attribute, form_options: )}, layout: false).to_s end |