The Rails 101 Blog Tutorial

Note: This tutorial assumes that a standard Ruby on Rails environment is configured. To set up such an environment automatically, use the 3rdRail "Ruby on Rails Install" available from the 3rdRail installation launcher.

Create a New Rails Project:

  1. Open the New Rails Project Wizard New Rails Project Wizard
    File| New Rails Project.
  2. Name the project:
    RailsDemo
  3. 3rdRail cannot create a new project unless the Ruby Interpreter is configured. If prompted, click Configure Interpreters... and select one in the dialog. Is no interpreters are shown, use the Search... button to locate one. The 3rdRail installation process includes a Ruby interpreter as part of the Ruby on Rails Install. Click OK to return to the wizard.
  4. This tutorial is compatible with both Rails 1.x and 2.x. Specifying an explicit Rails version is optional.
  5. Select the Database Type you are using. If you do not already have a database setup, the 3rdRail installation launcher provides the option to install either InterBase or MySQL. Both SQLite and InterBase support automatic database creation, while the remaining databases require use of the database specific interactive client to manually create a database for each project. SQLite 3 is installed by default on OS X 10.5 (Leopard). Specific steps for creating a database in MySQL are provided below.
  6. Click Finish to close the wizard.

Set up a Database:

  1. From the Rails Explorer navigate to:
    RailsDemo/config/database.yml
  2. Open the file in the Editor and add user name and password information for the RailsDemo_development database:
    database: RailsDemo_development
    user name: {username}
    password: {password}
    host: localhost
  3. Create the RailsDemo_development database:
    If your Database Type is either SQLite or InterBase, this database configuration step is unnecessary.
    Use the interactive database client to create the database. Specific steps for MySQL follow.
    Assuming that MySQL installed correctly, you have a user called root with a password you selected at install time. To start the MySQL client at the command line:
    mysql -u root -p
    Then at the MySQL client prompt type:
    mysql> create database RailsDemo_development;

Create the Model and Run the Migration:

  1. Open the
    New Rails Resource Wizard New Rails Resource Wizard
    File| New| Rails Model.
  2. Choose "RailsDemo" in the Project dropdown.
  3. Name the model:
    post
    Next, create the attributes for the post model.
  4. Type title in the Name column. By default it is a string type. Click in the Required field to open the Configure Required Validation Wizard. Check "Enabled". Click in the On field and select "save". Type "must be entered to save this post." in the Message field. Click Ok.
  5. Click Add to add another attribute. Type "content" in the Name column. Click in the type column and change the type to text. Click in the Required field to open the Configure Required Validation Wizard. Check "Enabled". Click in the On field and select "save". Type "must be entered to save this post." in the Message field. Click Ok.
  6. Click Add to add another attribute. Type "date" in the Name column. Click in the type column and change the type to datetime.
  7. Ensure that Run the Migration after creating the Model is checked.
    Ensure that Create a Scaffold for the generated Resource is checked.
  8. Click Finish.
  9. 3rdRail creates the model and controller, and opens the Ruby Editor.
    The Dependencies View shows outbound and inbound dependencies.
    The Project Commander shows the Rails code and hyperlinks to the generated files.
    Browse in the Rails Explorer to see all the elements of the Rails project.

Run the Application:

  1. Click the Embedded Mozilla Browser icon from the main Workbench Toolbar and enter the following URL:
    localhost:3000
    The Rails Welcome page displays.

    :

    If the application server does not automatically start, type "script/server" in the Project Commander.

  2. Modify the address in the browser to add "posts":
    localhost:3000/posts
    Notice the title, content, and date fields. Create a few blog posts to test the application.
  3. You can exit the application by pressing the Stop button located in the bottom right of the view frame.

Corporate LogoCodeGear brand and product names are service marks, trademarks or registered trademarks of Borland Software Corporation in the United States and other countries.