我正在使用Paperclip上傳多個圖像並將其存儲在s3中。 所以,我有一個畫廊模式,它看起來像這樣:Paperclip :: AdapterRegistry :: NoHandlerError嵌套的數據和存儲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,但它沒有幫助。 我試圖遵循this的答案,但我不確定我在哪裏將參數傳遞給回形針?
任何人都知道問題是什麼?謝謝
只是我在你的回形針配置已經注意到......哪裏是你鬥?你真的在哪裏保存圖像?您需要在您的aws支付中創建一個存儲桶 – Richlewis 2013-05-08 10:10:11
您的意思是: :storage =>:s3, :s3_credentials =>「#{Rails.root} /config/amazon_s3.yml」 我不知道該做什麼你的意思是鬥。對不起。 但我在其他模型(而不是nested_form)中使用回形針和s3,它的工作原理 – ishwr 2013-05-08 10:13:50
是什麼意思?認爲你錯過了那裏的東西 – Richlewis 2013-05-08 10:15:07