This might be a simple routing question in Rails but I have searched around and received answers for Rails 2 rather than Rails 3.
I generated a scaffold and the
resources :users
which includes new, edit, show are routed together with the index.
I only want to route to the index and remove the new, edit, show etc. I have already removed the html.erb files but they are still being routed.
Any advice on what I should do to remove the other routes would be appreciated.
In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.
The :only option tells Rails to create only the specified routes: resources :photos, :only => [:index, :show] Follow this answer to receive notifications.
TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.
Use the only
option:
resources :users, only: [:index]
Reference
See Chapter 4.6 of the Rails Routing Guide.
By default, Rails creates routes for the seven default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the :only and :except options to fine-tune this behavior. The :only option tells Rails to create only the specified routes:
resources :photos, :only => [:index, :show]
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