回形针中找不到图像(无路线匹配[Get])

时间:2012-08-21 06:57:42

标签: ruby-on-rails ruby ruby-on-rails-3 paperclip

我使用回形针进行图片上传:
我收到了错误:

Started GET "/assets/audios/thumbnails/7/thumb/4_X_4.jpg?1345530644"
for 127.0.0.1 at 2012-08-21 12:03:04 +0530
Served asset /audios/thumbnails/7/thumb/4_X_4.jpg - 404 Not Found (1ms)<br/>
ActionController::RoutingError (No route matches [GET] "/assets/audios/thumbnails/7/thumb/4_X_4.jpg"):<br/>

在我的模型中:

has_attached_file :thumbnail,
:styles => {:medium => "300x300>", :thumb => "100x100>"},
:url => "assets/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/assets/:class/:attachment/:id/:style/:basename.:extension" 

3 个答案:

答案 0 :(得分:2)

:url => "assets/...",
:path => ":rails_root/assets/..."

应该是

:url => "/assets/...",
:path => ":rails_root/public/assets/..."

虽然在资产目录中保存附件是一个糟糕的主意。您可以在files内添加另一个public

:url => "/files/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension"

保存在public/files内并使用/files网址会使网络服务器在rails之前点击文件(当然,正确配置您的网络服务器,例如nginx,是另一个问题)

答案 1 :(得分:0)

我在网上连续搜索后找到了正确的解决方案。我试图通过我能想到的所有概率来处理这个问题: - 权限,纠正路径,将服务器从webrick更改为thin。然后我研究了环境属性。 因此,以下是生产环境集内的正确答案:
  config.serve_static_assets = true
这解决了这个问题。

答案 2 :(得分:-6)

以下链接可以为您提供帮助:
Upload image using paperclip