by cmwright · 14y ago · 0 comments
The match statement is good for the occasional odd cases, but it has an :via option that can be used to restrict which HTTP actions it is allowed to match.
Edit: corrected below...thanks!
and there are almost no odd cases in fact. I would propose special route named "not_found" or "default" like route to be called if no routes found. Nice idea IMO, what do you think?
I had to use match when moving from Rails 2 to Rails 3 and parts of the route did not match the controller at all. But I think it was mostly because the upgrade plugin recommended it.
get '/foo' => 'foos#index', as: :foo
post '/foo' => 'foos#new', as: :new_foo
get '/foo/:id' => 'foos#show', as: :show_foo
put '/foo/:id' => 'foos#edit', as: :edit_foo
delete '/foo/:id' => 'foos#destroy', as: :destroy_foo
or scope them if you'd like: scope controller: "foo", constraints: { id: /0-9]+/ } do
get '/foo' => :index, as: :foo
post '/foo' => :new, as: :new_foo
put ...
delete ...
endAnd, again! PLEASE use method "data" instead of match :via => method. It's much better and looks clean.