One-Shot Scaffolding Creation
If you’re not that familiar with Rails, you might be creating your application domain entities (models, controllers, business objects, whatever you want to call them) like this:
ruby script/generate model Post
ruby script/generate controller Post
After which, you go in and edit the views for post to create the form with the title, body, etc. All manually.
The great news is that there’s a shortcut! This shortcut:
- Creates the model class
- Creates the views and controller
- Populates the new and edit views with the class’s fields
- Creates the schema migration with the class’s fields
How do you do it? Surprisingly easy:
ruby script/generate scaffold Post title:string body:text
Rails then takes those fields and populates them everywhere necessary. Brilliant! Easy! Use it, it’ll save you a few minutes of time (which adds up every time you need to create another class)!
Tags: generate, introductory, scaffolding Posted in


Leave a Reply