1. Home
  2. Computing & Technology
  3. Ruby

Ruby on Rails Tutorial - Starting the Blog

By , About.com Guide

4 of 8

Scaffolding

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.

Explore Ruby
By Category
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Ruby
  4. Ruby on Rails
  5. Scaffolding

©2010 About.com, a part of The New York Times Company.

All rights reserved.