How to make a route for both receiving and publishing?

I have it:

resources :users do

  collection do


  get 'blah'

  end

end

I want to do this action (blah) for both posts and now, maybe?

+3
source share
2 answers

You can simply enter the same name for the mail route as follows:

resources :users do
  collection do
    get 'blah'
    post 'blah'
  end
end

Both routes will have the same controller, action and url_helpers

+3
source

It looks like the verb restrictions are what you want.

match 'blah', to: 'users#blah', via: [:get, :post]

or

resources :users do
  collection do
    match 'blah', via: [:get, :post]
  end
end
+11
source

All Articles