28

I already have set up Devise to My App.
So User model is already generated, and exists by installing Devise

Now I'd like to add my own controller users_controller.rb and its views index and show.
How can I make scaffold without affecting to User model that already exists?

Igor Ivancha
  • 3,413
  • 4
  • 30
  • 39
MKK
  • 2,713
  • 5
  • 31
  • 51

3 Answers3

68

Try this ,

rails g scaffold_controller controller_name 

You will find more options via

rails generate -h
RailsEnthusiast
  • 1,251
  • 2
  • 12
  • 18
  • A sample output of scaffold_controller can be found at [this rails guide](http://guides.rubyonrails.org/command_line.html) – konyak Oct 15 '14 at 18:45
  • 2
    I would use model name and its attributes instead, so it could add the model's attributes to the output files also, e.g., `rails g scaffold_controller User first_name:string last_name:string` – konyak Oct 15 '14 at 19:01
20

For scaffold with only 'name' column:

rails g scaffold User name --skip

Just add some columns.

Look to rails g scaffold -h output for additional information.

denis.peplin
  • 9,585
  • 3
  • 48
  • 55
  • Thanks. What about the case that I'm not adding any column but I only want regular controller and regular views that'll be generated base on existing model. – MKK Jul 26 '12 at 04:51
  • You can input scaffold command manually (this way is faster if you have only one model to scaffold) or use script: http://stackoverflow.com/questions/6644713/how-do-you-generate-the-form-for-an-existing-model-in-rails – denis.peplin Jul 26 '12 at 05:11
  • @MKK you can generate scaffold for already created model e.g rails g scaffold_controller Your_Model_Name – Amir Khan Mar 09 '22 at 07:01
14

If you want just controller and views without the whole scaffold you can do:

rails generate controller Users index show
Sabar
  • 478
  • 2
  • 20
  • 4
    What I want is scaffold without generating new columns and affection to existing model – MKK Jul 26 '12 at 05:50