I am using Paperclip to upload multiple images and store it in s3. So, I have a gallery model, which looks like this :
class Gallery < ActiveRecord::Base
attr_accessible :title, :body, :pictures_attributes
has_many :pictures
accepts_nested_attributes_for :pictures, :allow_destroy => true
end
and gallery should have many picture. My picture model looks like this :
class Picture < ActiveRecord::Base
belongs_to :gallery
has_attached_file :picture, :styles => { :small => "150x150>", :medium => "300x300" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
:path => "/:class/:style/:id/:filename"
validates_attachment_presence :picture
validates_attachment_size :picture, :less_than => 5.megabytes
validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/png']
end
I already put this in my _form.html.erb :
<%= form_for @gallery, :html => { :multipart => true } do |f| %>
and this too
<%= f.fields_for :picture do |picture_form| %>
<p>
<%= picture_form.file_field :picture %>
</p>
<% end %>
In my galleries_controller, I have this :
def new
@gallery = Gallery.new
5.times{ @gallery.pictures.build }
end
# GET /galleries/1/edit
def edit
@gallery = Gallery.find(params[:id])
5.times{ @gallery.pictures.build }
end
# POST /galleries
# POST /galleries.xml
def create
@gallery = Gallery.new(params[:gallery])
respond_to do |format|
if @gallery.save
format.html { redirect_to(admin_gallery_path(@gallery), :notice => 'Gallery was successfully created.') }
format.xml { render :xml => @gallery, :status => :created, :location => @gallery }
else
format.html { render :action => "new" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
I found some similar case, followed the answer. But I still got the same error message. I tried to change RAILS_ROOT to Rails.root, but it didn't help. I tried to follow this answer, but I am not sure where do I pass the params to the paperclip?
Anyone knows what the problem is? Thanks