Paperclip在开发环境中可以工作但在生产环境中无法工作?

6
我对rails比较新,似乎在使用paperclip gem过程中出现了问题。我已安装gem并且在开发环境(localhost:3000)下完美运行,但是当我在heroku服务器上运行时,它不想附加文件,应用程序会崩溃(错误500页面)。
这是我运行的过程...我将文件推送到heroku,heroku 运行rake db:migrate (添加paperclip migrations),然后我运行 heroku restart (使用新迁移重新启动应用程序)。但这似乎没有起作用。
以下是我用于paperclip的代码: 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']

编辑_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

再次遇到问题,不知为何在开发环境中运行良好,在生产环境中却出现了故障。如有任何指点,将不胜感激...我似乎无法解决这个问题,而且相当沮丧。非常感谢您的时间和帮助!

2个回答

3
在你的模型中。
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/


非常感谢您的帮助,我一定会去做的。谢谢! - slovak_100

1

非常感谢你,Jake!我真的很感激...我不知道我不能上传到Heroku,但回想起来这完全有道理。非常感谢你,伙计!! - slovak_100

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接