0
美好的一天,这里有很多关于这个问题的问题,但他们不帮助我。“显示”动作的路由错误
对于signed_in
用户我有一个主页bookmarks
和folders
,其中包含属于此文件夹的书签。
home
方法是static_pages
控制器,它看起来是这样的:
def home
if signed_in?
@folder = current_user.folders.build
@folders = current_user.folders.all
@bookmark = current_user.bookmarks.build
@bookmarks = current_user.bookmarks.all
end
end
这是home.html.erb
<div class="span3">
<table class="table table-hover table-condensed">
<%= render @bookmarks %>
</table>
</div>
<div class="span3">
<table class="table table-hover table-condensed">
<%= render @folders %>
</table>
</div>
所以部分,我有2代表与所有bookmarks
和所有folders
,属于current_user
这是_folder.html.erb
从folders
文件夹中views
<tr data-toggle="tooltip" data-placement="right" data-html="true">
<td data-href="<%= folder %>" class="bookmark"><i class="icon-folder-close"></i>
<%= link_to folder.name, folder_path %>
</td>
<td>
<%= link_to '<i class="icon-edit"></i>'.html_safe, '#' %>
</td>
<td>
<%= link_to '<i class="icon-trash"></i>'.html_safe, folder_path, method: :delete,
data: {confirm: 'Are you sure?'},
title: 'Delete folder ' + folder.name.to_s %>
</td>
</tr>
folders_controller.rb
,与show
方法:
def show
@folder = Folder.find(params[:id])
@bookmarks = @folder.bookmarks.all
end
也resources :folders
存在routes.rb
所有我需要的是去localhost:3000/folder/1
,在主页上folder_name
点击时。
这就是我得到:
Routing Error
No route matches {:action=>"show", :controller=>"folders"}
在rake routes
一切正常。
当在浏览器中放入localhost:3000/folder/1
时,它工作正常。
谢谢!
我已经试过这一点,但它并不能帮助我。现在,当点击'folder_name'时,我在地址栏中看到:'http:// localhost:3000 /#',但它仍然不访问'folder/1'。 –
2013-05-01 05:18:57
尝试'folder_path(folder.id)'或'folder_path(:id => folder.id)' – Wasi 2013-05-01 13:31:48