Chirantan
Chirantan

Reputation: 15634

Changing default REST actions in rails

I want to be able to change the default mapping of actions with RESTful url and type of request.

For example,

After adding map.resources :fruits in the routes, by default, sending a GET request to /fruits/:id calls show action in fruits controller. However, I would like to call a custom action, say display, in the fruits controller instead of show action. How do I do it? This has to be a route configuration.

Upvotes: 2

Views: 1974

Answers (1)

gdelfino
gdelfino

Reputation: 11181

I would like to recommend you to read this page:

http://guides.rubyonrails.org/routing.html

It explains in detail all aspects related to routing.

Using :path_names you can customize the new and edit generated paths. If you want to change GET /fruits/:id from activating the show action to activating a display action, then the change is invisible to the user. And you would be deviating from the flow with no apparent reason.

Upvotes: 1

Related Questions