I'm new to Rails so my current project is in a weird state.
One of the first things I generated was a "Movie" model. I then started defining it in more detail, added a few methods, etc.
I now realize I should have generated it with
rails generate scaffold to hook up things like the routing, views, controller, etc.
I tried to generate the scaffolding but I got an error saying a migration file with the same name already exists.
What's the best way for me to create scaffolding for my "Movie" now? (using rails 3)
rails g scaffold_controller <name>
Even though you already have a model, you can still generate the necessary controller and migration files by using the
rails generateoption. If you run
rails generate -hyou can see all of the options available to you.
If you'd like to generate a controller scaffold for your model, see
scaffold_controller. Just for clarity, here's the description on that:
To create your resource, you'd use the
resourcegenerator, and to create a migration, you can also see the
migrationgenerator (see, there's a pattern to all of this madness). These provide options to create the missing files to build a resource. Alternatively you can just run
rails generate scaffoldwith the
--skipoption to skip any files which exist :)
I recommend spending some time looking at the options inside of the generators. They're something I don't feel are documented extremely well in books and such, but they're very handy.