1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Ruby on Rails Tutorial - Starting the Blog


4 of 8


Rails provides an interface to get web applications up and running quickly. The scaffolding generator will create a model, controller and migration that can be edited to your needs. Pass as arguments to the scaffold generator the name of the model you'd like to create, as well as the names and types of fields the model should have.

blog$ script/generate scaffold Post title:string body:text
      exists app/models/
      exists app/controllers/
      exists app/helpers/
      create app/views/posts
      exists app/views/layouts/
      exists test/functional/
      exists test/unit/
      exists public/stylesheets/
      create app/views/posts/index.html.erb
      create app/views/posts/show.html.erb
      create app/views/posts/new.html.erb
      create app/views/posts/edit.html.erb
      create app/views/layouts/posts.html.erb
... snip ...

The Post model has now been created. In the migration, you can see that the posts SQL table will be created with two columns--a title as a string and a body as text. The difference between string and text is the length allowed. String should be short, no more than 200 characters or so. That's fine for the title, but the body of the blog posts need more space. The text column type has no limits on length, and thus are much more appropriate for blog post bodies.

  1. About.com
  2. Technology
  3. Ruby
  4. Ruby on Rails
  5. Scaffolding

©2014 About.com. All rights reserved.