在我的开发环境中,我可以成功使用paperclip创建下载。在生产中,将创建下载,但下载链接不起作用。
在开发中创建的链接:
http://localhost:3000/downloads/files/3?1345315475
生产中创建的链接:
http://www.domain.com/attachments/original/missing.png
以下是创建下载时的生产日志:
Started POST "/downloads" for xxx.xxx.xxx.xxx at 2012-08-18 11:47:31 -0700
Processing by DownloadsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JhFMcjaui8cb4HCxTiIOjb/R2uxVJcOv3WEz8V0yoPp=", "download"=>{"school_id"=>"1", "software"=>"Follett", "original"=>"1", "makeup"=>"0", "visible"=>"1", "expired"=>"0"}, "commit"=>"Create Download"}
[paperclip] Saving attachments.
Rendered download_notice_mailer/download_notice.html.erb (1.9ms)
当我在控制台(生产)中搜索下载时
irb(main):001:0> d = Download.last
Download Load (0.4ms) SELECT `downloads`.* FROM `downloads` ORDER BY `downloads`.`id` DESC LIMIT 1
=> #<Download id: 8, visible: true, expired: false, software: "Skyward", created_at: "2012-08-18 19:01:35", updated_at: "2012-08-18 19:01:35", school_name: "SCHOOL NAME", original: true, makeup: false, attachment_file_name: nil, attachment_content_type: nil, attachment_file_size: nil, attachment_updated_at: nil, school_id: 8, district_id: 2>
您会注意到所有附件属性都是零。
我使用的是rails 3.2.8和paperclip 3.1.4
我的download.rb模型文件的一部分
has_attached_file :attachment, :path => (Rails.root + "downloads/files/:id").to_s,
:url => "/downloads/files/:id"
validates_attachment_presence :attachment
attr_accessible :visible, :expired, :software, :school_name, :original, :makeup, :attachment, :school_id, :district_id
如果需要任何其他信息,请告知我们。
谢谢,
答案 0 :(得分:1)
...解决
看起来我在.gitignore文件中列出/下载/文件是为了防止测试下载被转移到服务器。我发现服务器上缺少/ downloads / files目录,回形针正在将文件放入/下载(我可能会添加错误)。因此,在下载中创建文件目录后,一切都按预期工作。