Module: Directlytos3::FormHelpers
- Defined in:
- lib/directlytos3/form_helpers.rb
Instance Method Summary collapse
- #s3_field_tag(name, options = {}) ⇒ Object
- #s3_form_for(record, *args, &block) ⇒ Object
- #s3_hidden_fields(options) ⇒ Object
Instance Method Details
#s3_field_tag(name, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/directlytos3/form_helpers.rb', line 38 def s3_field_tag(name, = {}) Directlytos3::configure() url = [:path] || "https://#{[:bucket]}.s3.amazonaws.com/" form_tag(url, :remote => [:remote], :enctype=>"multipart/form-data",:method=>"post", :id => 's3-upload-form', :authenticity_token => false) do s3_hidden_fields() concat file_field_tag 'file' end end |
#s3_form_for(record, *args, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/directlytos3/form_helpers.rb', line 52 def s3_form_for(record, *args, &block) raise ArgumentError, "s3_form_for: Missing block" unless block_given? = args. url = [:path] || "https://#{[:bucket]}.s3.amazonaws.com/" args << {:url => url, :builder => [:builder], :enctype => "multipart/form-data", :method => "post", :html => {:id => 's3-upload-form'}, :authenticity_token => false, :remote => [:remote]} Directlytos3::configure() form_for(record, *(args)) do |f| s3_hidden_fields() block.call(f) # f.file_field "file", :name => "file" end end |
#s3_hidden_fields(options) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/directlytos3/form_helpers.rb', line 66 def s3_hidden_fields() policy = Directlytos3::S3.policy() signature = Directlytos3::S3.signature() concat hidden_field_tag('key', "#{[:key]}#{'/' if ![:key].blank?}#{Directlytos3.random_string if [:randomize]}${filename}") concat hidden_field_tag('AWSAccessKeyId', "#{[:access_key]}") concat hidden_field_tag('acl', "#{[:acl]}") concat hidden_field_tag('success_action_redirect', "#{[:redirect]}") if [:redirect] concat hidden_field_tag('success_action_status', "#{[:status].to_s}") if [:status] concat hidden_field_tag('policy', "#{policy}") concat hidden_field_tag('signature', "#{signature}") concat hidden_field_tag('Content-Type', "#{[:content_type]}") concat hidden_field_tag('Cache-Control', "public,max-age=#{[:cache_control]}") if [:cache_control] .except!(:key, :access_key, :acl, :redirect, :content_type, :secret_key, :randomize, :expiration_date, :max_filesize, :path, :status) end |