本文介绍了回形针工作在发展但不在生产中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对轨道很陌生,似乎对回形针宝石有问题。我安装了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 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

同样,由于某种原因,它在开发中运行良好,但在生产中出现故障。任何指针将不胜感激......我似乎不能解决这个问题,这是非常令人沮丧的。非常感谢您的时间和任何帮助!

解决方案

在您的模型中。

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



配置目录:

 开发:
bucket:bucketname
access_key_id:key
secret_access_key:key

制作:
存储桶:存储桶名称
access_key_id:存储钥匙
secret_access_key:钥匙

然后注册Amazon S3中的存储桶:


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!

解决方案

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/

这篇关于回形针工作在发展但不在生产中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:03