rake routes
這裏是你的朋友。它會吐出你生成的路由列表 - 當你有一堆嵌套或自定義路由時特別有用。
的路徑將是
admin_pages_path #(with GET) routes to :controller => 'admin/pages', :action => 'index'
admin_pages_path #(with POST) routes to :controller => 'admin/pages', :action => 'create'
new_admin_page_path #(with GET) routes to :controller => 'admin/pages', :action => 'new'
edit_admin_page_path(:id) #(with GET) routes to :controller => 'admin/pages', :action => 'edit'
admin_page_path(:id) #(with GET) routes to :controller => 'admin/pages', :action => 'show'
admin_page_path(:id) #(with PUT) routes to :controller => 'admin/pages', :action => 'update'
admin_page_path(:id) #(with DELETE) routes to :controller => 'admin/pages', :action => 'delete'
您的刪除的link_to因此應該是:
<%= link_to("delete page", admin_page_path(@page), :confirm => "sure you want to delete this page?", :method => :delete) %>
注意,Rails會工作它的魔力,呼籲@page to_param
,讓您不必指定@ page.id - 對於像這樣的例子很有用,因爲您經常想爲「網頁」使用永久鏈接。
謝謝邁爾斯, 我誤解了耙路線的輸出。 亞當 – apchester 2009-07-21 11:47:55