使用资源路由创建的等效匹配路由是什么?
请确切。
例如,等效的匹配是什么:
resources :users
应该有7种不同的匹配路线匹配7个动作 - 索引,新建,创建,编辑,更新,显示和删除。这是其中之一:
Http方法:新(获取行动)
match "users/new", :to => "users#new", :via => :get, :as => :new_user
我还有一些,但我想确认一下我对社区的看法。谢谢!
答案 0 :(得分:6)
我想你想知道路由文件中的代码应该是什么......
match "users/:id", :to => "users#show", :via => :get, :as => :user
match "users", :to => "users#index", :via => :get, :as => :users
match "users", :to => "users#create", :via => :post
match "users/:id/edit", :to => "users#edit", :via => :get, :as => :edit_user
match "users/:id", :to => "users#update", :via => [:put, :patch]
match "users/new", :to => "users#new", :via => :get, :as => :new_user
match "users/:id", :to => "users#destroy", :via => :delete
答案 1 :(得分:1)
你是对的,它确实提供了7种不同的路线。来自Rails Guides
resources :users
提供7种不同的路由,所有这些路由都将映射到用户控制器。
这些路线将是
GET /photos index display a list of all photos
GET /photos/new new return an HTML form for creating a new photo
POST /photos create create a new photo
GET /photos/:id show display a specific photo
GET /photos/:id/edit edit return an HTML form for editing a photo
PUT /photos/:id update update a specific photo
DELETE /photos/:id destroy delete a specific photo