回形针在开发中工作但在生产中不起作用?
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的模型中。
在配置目录中的 s3.yml 中:
然后在 Amazon S3 上注册存储桶: http://aws.amazon .com/s3/
In your model.
In s3.yml in your config dir:
Then go signup for a bucket at Amazon S3: http://aws.amazon.com/s3/
您可能遇到一些问题。但是,首先是您无法写入 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