1
votes

I do not want to use scaffold in my rails app and there is something I do not quite get (yet!) regarding the "resources" keyword in the routes.rb.
Is the usage of "resources" linked to the generation with "scaffold" ?
My understanding is that "scaffold" will create a bunch of files, and among them a controller with the correct action's names (index, show, ...).
If I create the model (without using "scaffold") and then create a controller with the correct actions and the correct views, would this be sufficient to use "resources" in the routes.rb or will I miss something ?

1

1 Answers

1
votes

Scaffold and resources is not linked in any way.

It's just that resources is already a kind of scaffold in that it always creates the CRUD routes that are also generated by the scaffold.

So if you write:

resources :users

You end up creating 6 routes for:

  • index
  • new
  • create
  • edit
  • update
  • destroy

You can limit what resources are generated by using :only

resources :users, :only => [:index, new]

Where only the index and new routes will be created.

You then can create those actions in your controller and add the appropriate views for them.

In short: If you just put resources :users in your routes.rb you can create these actions yourself in the controller and it will just work. No need to create a scaffold for it.