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

发布于 2024-11-30 07:06:49 字数 1090 浏览 1 评论 0原文

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

这是我运行的过程...我将文件推送到heroku,heroku运行rake db:migrate(以添加回形针迁移),然后运行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

同样,由于某种原因,它在开发中运行良好,但在生产中崩溃。任何指示将不胜感激...我似乎无法弄清楚这一点,这非常令人沮丧。非常感谢您的时间和任何帮助!

I'm pretty new to rails and seem to be having an issue with the paperclip gem. I installed the gem and it works well in development (localhost:3000) but when I'm running it on the heroku server, for some reason it does not want to attach files, and the app breaks (error 500 page).

Here is the process i ran... I pushed my file to heroku, heroku ran rake db:migrate (to add paperclip migrations), and then I ran heroku restart (to restart the app with new migrations). This did not seem to help.

Here is the code that I have for paperclip:

user.rb model:

  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 view:

  = 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

Again, for some reason it runs great in development, but breaks down in production. Any pointers would be greatly appreciated... I just cant seem to figure this out and it's pretty frustrating. Thank you so much for your time and any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-12-07 07:06:49

在你的模型中。

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/

In your model.

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

In s3.yml in your config dir:

    development:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

    production:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

Then go signup for a bucket at Amazon S3: http://aws.amazon.com/s3/

清旖 2024-12-07 07:06:49

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

You could be having a few problems. However, the first is that you can not write to the file system on Heroku. You will have to implement a different storage mechanism such as s3. You can read about this limitation here: http://devcenter.heroku.com/articles/read-only-filesystem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文