i raised a similar question here....use paperclip >= 4
along with s3
to make this 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 this
@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"}) do |f |%>
<%= f.fields_for :image_photos do |builder| %>
<% if builder.object.new_record? %>
Upload picture
<!-- to add multiple images-->
<%= builder.file_field :avatar,:multiple=>"true",:name=>"image_photos[avatar] []",:class=>"opacity"%></a>
<%end%>
<%end%>