Paperclip :: AdapterRegistry :: NoHandlerError嵌套数据和存储s3

时间:2013-05-08 09:59:21

标签: ruby-on-rails-3 amazon-s3 paperclip nested-forms

我正在使用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,但它没有帮助。 我试着按this回答,但我不知道我在哪里将params传递给回形针?

有谁知道问题是什么?谢谢

1 个答案:

答案 0 :(得分: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账户中创建存储桶