Я использую Paperclip для загрузки нескольких изображений и сохранения их в s3. Итак, у меня есть модель галереи, которая выглядит так:
class Gallery < ActiveRecord::Base
attr_accessible :title, :body, :pictures_attributes
has_many :pictures
accepts_nested_attributes_for :pictures, :allow_destroy => true
end
и в галерее должно быть много картинок. Моя фотомодель выглядит так:
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
Я уже поместил это в свой _form.html.erb:
<%= form_for @gallery, :html => { :multipart => true } do |f| %>
и это тоже
<%= f.fields_for :picture do |picture_form| %>
<p>
<%= picture_form.file_field :picture %>
</p>
<% end %>
В моем Galleries_controller у меня есть это:
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
Я нашел похожий случай, последовал ответ. Но я все еще получаю то же сообщение об ошибке. Я попытался изменить RAILS_ROOT на Rails.root, но это не помогло. Я попытался выполнить этот ответ, но я не уверен, куда передать параметры скрепке?
Кто-нибудь знает, в чем проблема? Спасибо