2011-08-18 113 views
6

我很新的轨道,似乎有问题与回形针宝石。我安装了gem,它在开发(localhost:3000)中运行良好,但是当我在heroku服务器上运行它时,出于某种原因它不想附加文件,并且应用程序中断(错误500页)。paperclip在开发中工作,但不在生产中工作?

下面是我跑过的过程...我将文件推送到heroku,heroku运行rake db:migrate(添加回形针迁移),然后运行heroku restart(重新启动应用程序,并进行新的迁移)。这似乎没有帮助。

这里是我有回形针代码:

user.rb型号:

has_attached_file :avatar, 
        :styles => {:small => "70x70>"}, 
        :url => "https://stackoverflow.com/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 

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

回答

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 

然后去注册一个水桶在亚马逊S3:http://aws.amazon.com/s3/

+0

非常感谢你为此......我一定会去做那件事。谢谢! –

1

您可能会遇到一些问题。但是,首先是你不能在Heroku上写入文件系统。你将不得不实现一个不同的存储机制,比如s3。您可以在此阅读有关此限制的信息:http://devcenter.heroku.com/articles/read-only-filesystem

+0

非常感谢这个,杰克!我真的很感激它......我不知道我无法上传到Heroku,但回想起来它完全有意义。非常感谢你,队友! –

相关问题