2012-11-02 94 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