30

I've setup a simple app and added a scaffold to do some of the work for me (I'm a noob).

  resources :cars

How do I remove certain actions from the routes? And remove the corresponding urls?

For example I want to keep the 'show' and 'edit' actions & urls.

But I don't want there to be a 'new' 'index' or 'delete'

I understand this is probably a really simple question, but I've not been able to find an answer.

Taryn East
  • 27,486
  • 9
  • 86
  • 108
Finnnn
  • 3,530
  • 6
  • 46
  • 69

2 Answers2

57
resources :cars, :except => [:new, :index, :delete]

or

resources :cars, :only => [:show, :edit]

Also take a look at Rails Guides

Mikhail Nikalyukin
  • 11,867
  • 1
  • 46
  • 70
1
If you want to remove some actions then you can mention action name in the array

resources :photos, only: [:index, :show]

But

if you want to disable all the default CRUD actions then you should use
    
resources :photos, only: []
Jigar Bhatt
  • 4,217
  • 2
  • 34
  • 42