2013-05-08 35 views
1

我正在使用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的答案,但我不確定我在哪裏將參數傳遞給回形針?

任何人都知道問題是什麼?謝謝

+0

只是我在你的回形針配置已經注意到......哪裏是你鬥?你真的在哪裏保存圖像?您需要在您的aws支付中創建一個存儲桶 – Richlewis 2013-05-08 10:10:11

+0

您的意思是: :storage =>:s3, :s3_credentials =>「#{Rails.root} /config/amazon_s3.yml」 我不知道該做什麼你的意思是鬥。對不起。 但我在其他模型(而不是nested_form)中使用回形針和s3,它的工作原理 – ishwr 2013-05-08 10:13:50

+0

是什麼意思?認爲你錯過了那裏的東西 – Richlewis 2013-05-08 10:15:07

回答

0

好吧,我可以看到你似乎錯過了一個(存儲桶)的地方來存儲你的照片在AWS中。生病告訴你我的意思

has_attached_file :avatar, 
:styles => {:thumb => "100x100>" }, 
:storage => :s3, 
:s3_credentials => "#{Rails.root}/config/s3.yml", 
:path => "/images/:id/:style.:extension", 
:url => ":s3_domain_url", 
:bucket => "assets.recipesapp" 

爲例,用戶您的AWS賬戶內創建桶

+0

雖然在我的lib> paperclip>存儲我已經有s3.rb,我仍然必須在paperclip配置添加:桶? 在其他課程中使用我也使用回形針,而不添加存儲桶 – ishwr 2013-05-08 10:24:00

+0

好吧,那麼您如何通過AWS查看這些圖像,因爲您可以登錄到您的帳戶並查看所有資產?這是我怎麼做的,過去沒有問題,試試吧? – Richlewis 2013-05-08 10:26:35

+0

我試了一下,但仍然得到了同樣的錯誤:( – ishwr 2013-05-08 10:33:39

相關問題