Noz*_*Noz 6 routing get paperclip ruby-on-rails-3
在我的节目视图中,每当我尝试使用image_tag构建器显示图像时,rails都不会在我的节目视图中的公共文件夹中查找图像...
例如:
<%= image_tag "thumbnails/fish.jpg" %>
Run Code Online (Sandbox Code Playgroud)
会产生这个:
ActionController::RoutingError (No route matches [GET] "/uploads/thumbnails/fish.jpg"):
Run Code Online (Sandbox Code Playgroud)
我正在使用回形针Gem作为我的上传模型,出于安全原因,我将上传保存到与公用文件夹不同的文件夹中,是的,此显示视图确实发生在上传控制器中...
在我的上传模型中,我使用此行将上传保存到非公共文件夹:
has_attached_file :upload, :path => ":rails_root/:class/:id/:basename.:extension",
:url => ":rails_root/:class /:id/:basename.:extension"
Run Code Online (Sandbox Code Playgroud)
耙路线:
upload GET /uploads/:id(.:format) {:action=>"show", :controller=>"uploads"}
PUT /uploads/:id(.:format) {:action=>"update", :controller=>"uploads"}
DELETE /uploads/:id(.:format) {:action=>"destroy", :controller=>"uploads"}
/download/:id(.:format) {:controller=>"uploads", :action=>"download"}
Run Code Online (Sandbox Code Playgroud)
编辑 注意:如果我明确地创建一个img标记并将src指向我的图像,它在我的节目视图中工作正常,所以我不认为这是一个权限问题.
答案很简单,我无法相信Rails是如此挑剔但我需要在路径的开头包含一个正斜杠,如下所示:
"thumbnails/fish.jpg"
Run Code Online (Sandbox Code Playgroud)
变
"/thumbnails/fish.jpg"
Run Code Online (Sandbox Code Playgroud)
我仍然很好奇为什么这只是非索引视图的问题...
| 归档时间: |
|
| 查看次数: |
8476 次 |
| 最近记录: |