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