开发者

get, match and resources in routes.rb

I am new to Rails. I开发者_如何学运维 found it very strange when I use the resources in routes.rb, after I redirect the page to controller/index, it render the controller/show .

I know GET controller/action is same as match "controller/action", :to => "controller/action"

I think the strange thing happens to me about the redirect, is similar to the GET and Match.

so I wonder what exactly the resources mean, can I use some simple match do the same thing?


resources is a shortcut for generating seven routes needed for a REST interface.

resources :widgets is equivalent to writing

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'

it just saves you the trouble.

By the way, get is not exactly the same as match. get, post, put and delete are shortcuts for limiting the route to a single HTTP verb. The two route definitions below are equivalent.

match 'foo' => 'controller#action', :method => :get
get   'foo' => 'controller#action'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜