I want to route the same address, e.g., 'http://server/path' to different controller actions depending on the request type, whether it is a GET or POST request.
How can I do that in Rails?
Thanks!
Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions. Each action's purpose is to collect information to provide it to a view.
Difference between singular resource and resources in Rails routes. So far, we have been using resources to declare a resource. Rails also lets us declare a singular version of it using resource. Rails recommends us to use singular resource when we do not have an identifier.
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
get "/path" => "controller#get_action"
post "/path" => "controller#post_action"
I think you could do this:
match '/path' => 'controller#action', :via => :get
match '/path' => 'controller#another_action', :via => :post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With