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:

  1. Creates the model class
  2. Creates the views and controller
  3. Populates the new and edit views with the class’s fields
  4. 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)!

About Ashiq Alibhai

Ashiq Alibhai, PMP, has been a Rails aficionado since 2007, and developed web applications since early 2003, where he learned PHP in one summer. As the driving-force behind RailsRocket and the Launchpad project, he seeks to share the ease of development with Rails far and wide.
This entry was posted in Development and tagged , , . Bookmark the permalink.

Comments are closed.