1

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 %>

私の gallery_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 に変更しようとしましたが、役に立ちませんでした。この回答に従おうとしましたが、どこでパラメーターをペーパークリップに渡すのかわかりませんか?

誰が問題が何であるか知っていますか?ありがとう

4

1 に答える 1

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 アカウント内でバケットを作成します

于 2013-05-08T10:18:36.653 に答える