我知道GET controller/action
与match "controller/action", :to => "controller/action"
我认为关于重定向发生了奇怪的事情,类似于GET和Match。
所以我想知道资源究竟是什么意思,我可以使用一些简单的匹配做同样的事情吗?
答案 0 :(得分:23)
resources
是生成REST界面所需的七条路线的快捷方式。
resources :widgets
相当于写作
get "widgets" => "widgets#index", :as => 'widgets'
get "widgets/:id" => "widgets#show", :as => 'widget'
get "widgets/new" => "widgets#new", :as => 'new_widget'
post "widgets" => "widgets#create", :as => 'widgets'
get "widgets/:id/edit" => "widgets#edit", :as => 'edit_widget'
patch "widgets/:id" => "widgets#update", :as => 'widget'
put "widgets/:id" => "widgets#update", :as => 'widget'
delete "widgets/:id" => "widgets#destroy", :as => 'widget'
它只是为您省去了麻烦。
顺便说一下,get
与match
并不完全相同。 get
,post
,put
和delete
是将路由限制为单个HTTP谓词的快捷方式。下面的两个路线定义是等效的。
match 'foo' => 'controller#action', :method => :get
get 'foo' => 'controller#action'