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

slo*_*100 6 ruby-on-rails heroku production-environment paperclip

我对rails非常陌生并且似乎对回形针宝石存在问题.我安装了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']
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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

the*_*gah 3

在你的模型中。

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

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

    development:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

    production:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key
Run Code Online (Sandbox Code Playgroud)

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