ruby - Rails nested multi file upload to amazon s3 using s3_file_field -


i've been trying multi image uploads working on nested model in rails. i've been using s3_file_field gem, can found here.

i've created gist shows relevant parts of code available here.

when try upload 2 images, both images uploaded s3, 1 image object saved database. need find way create image object each image uploaded s3.

i raised similar question here....use paperclip >= 4 along s3 make work.

class image < activerecord::base   has_many :image_photos , :dependent => :destroy   accepts_nested_attributes_for :image_photos, :reject_if => lambda { |a| a[:avatar].blank? }, :allow_destroy => true end   class imagephoto < activerecord::base  belongs_to :image  has_attached_file :avatar,   :styles => {:view => "187x260#"},   :storage => :s3,   :s3_permissions => :private,   :s3_credentials => s3_credentials  attr_accessible :image_id,:avatar,:avatar_file_name,:avatar_content_type,:avatar_file_size,:avatar_updated_at  validates_attachment_content_type :avatar, :content_type => /\aimage\/.*\z/  validates_presence_of :avatar end 

in controller

 def new if current_or_guest_user.pic_categories.present?  @image = image.new  #3.times {@image.image_assets.build} # added  @image.image_photos.build  end    def create @image = image.new(params[:image]) @image.user_id = current_or_guest_user.id  if @image.save    if params[:image_photos][:avatar]      params[:image_photos][:avatar].each { |image|        @image.image_photos.create(avatar: image)        }       end @image.create_activity key: 'image.create', owner: current_or_guest_user end 

_form.html.erb

<%= form_for(@image,:html=>{:multipart => true,:remote=>true,:class=>"form-horizontal",:role=>"form"}) |f |%>  <%= f.fields_for :image_photos |builder| %> <% if builder.object.new_record? %>    upload picture   <!-- add multiple images-->    <%= builder.file_field :avatar,:multiple=>"true",:name=>"image_photos[avatar]  []",:class=>"opacity"%></a>  <%end%>   <%end%> 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -