Butter Beer
Butter Beer

Reputation: 1150

Rails route to only index

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.

Upvotes: 43

Views: 43559

Answers (2)

Rodrigo
Rodrigo

Reputation: 4802

Use the only option:

resources :users, only: [:index]

Reference

Upvotes: 87

Mike Campbell
Mike Campbell

Reputation: 7978

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]

Upvotes: 14

Related Questions