回形针在开发中工作但不在生产中工作?

我对rails非常陌生并且似乎对回形针gem存在问题。 我安装了gem并且它在开发中运行良好(localhost:3000)但是当我在heroku服务器上运行它时,由于某种原因它不想附加文件,并且应用程序中断(错误500页)。

这是我运行的过程…我将我的文件推送到heroku,heroku运行rake db:migrate(添加paperclip迁移),然后我运行heroku restart(重新启动应用程序的新迁移)。 这似乎没有帮助。

这是我用于回形针的代码:

user.rb模型:

has_attached_file :avatar, :styles => {:small => "70x70>"}, :url => "/users/:attachment/:id/:style/:basename.:extension", :path => ":rails_root/public/users/:attachment/:id/:style/:basename.:extension" validates_attachment_size :avatar, :less_than => 500.kilobytes validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png'] 

edit_form.html.haml视图:

  = form_for (@user || User.new), :html => { :multipart => true } do |f| ... .profile_picture.text_field = image_tag current_profile.avatar.url(:small) %br = f.file_field :avatar 

同样,由于某种原因,它在开发中运行良好,但在生产中出现故障。 任何指针都会非常感激……我似乎无法弄清楚这一点,这非常令人沮丧。 非常感谢你的时间和任何帮助!

在你的模型中。

 has_attached_file :picture, :styles => {:large => "275x450>"}, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "appname/:attachment/:style/:id.:extension" 

在配置目录中的s3.yml中:

  development: bucket: bucketname access_key_id: key secret_access_key: key production: bucket: bucketname access_key_id: key secret_access_key: key 

然后在Amazon S3上注册一个桶: http : //aws.amazon.com/s3/

你可能遇到了一些问题。 但是,首先是你无法写入Heroku上的文件系统。 您必须实现不同的存储机制,例如s3。 您可以在此处阅读有关此限制的信息: http : //devcenter.heroku.com/articles/read-only-filesystem