开发者

Routing Error with Rails 3 Paperclip and S3

I followed this tutorial exactly and received the following error after trying to upload a JPG to my local environment (I have not pushed to Heroku yet):

ActionController::RoutingError (No route matches "/logos/medium/missing.png")

I checked similar tutorials and none of them mentioned requiring routes for your remote images. Like I said, I have triple-checked this tutorial and I'm doing every开发者_如何学Cthing it asks of me, so what steps could I be missing here? The ONLY difference is that I already had specified a "photo" column in my model as a binary datatype with the same name as the has_attached_file variable...could that be causing the conflict?


I was about to delete this when I realized it will be valuable for others to learn what went wrong.

So if you follow that tutorial to the tee you will do just fine. HOWEVER, if you use attr_accessible to protect the attributes of your model, you need to specify ALL of them in your model in order to make these images actually save to your S3 bucket.

A hint will be if you see the following in your logs:

WARNING: Can't mass-assign protected attributes: photo

This lets you know that you have protected columns in your database that need to be exposed through attr_accessible

Here's what the code would look like if you were to follow the example tutorial I provided in my question:

class Product < ActiveRecord::Base
  attr_accessible :photo, :photo_file_name, :photo_content_type, :photo_file_size, :photo_updated_at
  belongs_to :page
  has_attached_file :photo,
    :styles =>{
      :thumb  => "100x100",
      :medium => "200x200",
      :large => "600x400"
    },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => ":attachment/:id/:style.:extension",
    :bucket => 'yourbucket'
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜