2012-11-02 90 views
0

我有一系列我希望編輯的項目。當編輯我的網址的當前格式顯示爲這樣:導軌路線配置

http://mysite/items <---- Lists the items 
http://mysite/items/1/ <------ more detailed view of items 
http://mysite/items/1/edit <----- Ability to edit the item 

路由配置我想嘗試並應用到我的結構想是這樣的:

http://mysite/items <---- Lists the items 
http://mysite/item <---- Detailed view of the item by sending the item ID as POST data 
http://mysite/item/edit <---- Edits the item by sending the item ID as POST data 

這是嚴格意義上的事件的軌道路由配置,還是必須配置items頁面中的鏈接來專門構建URL。

+0

只是我的看法,如果你設置URL像'http:// mysite/item',你怎麼知道你將顯示​​哪個ID的項目? – Thanh

回答

0

試試這個:

#config/routes.rb 
#assuming your actions are in ItemsController 
match 'items' => 'items#index', :via => :get 
match 'item' => 'items#show', :via => :post 
match 'item/edit' => 'items#edit', :via => :post 

要知道這是更多的傳統應用程序/網址爲Rails約定如下RESTful的映射。進一步的信息在the routing guide