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:
-
Open the
New Rails Project Wizard
-
Name the project:
RailsDemo
-
3rdRail cannot create a new project unless the Ruby Interpreter
is configured. If prompted, click
and select one in the dialog. Is no interpreters are shown, use the button to locate one.
The 3rdRail installation process includes a Ruby interpreter as part of the .
Click to return to the wizard.
-
This tutorial is compatible with both Rails 1.x and 2.x. Specifying an explicit Rails version is
optional.
-
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 or . Both and support automatic database creation, while the remaining databases require use of the database specific interactive client
to manually create a database for each project. is installed by default on OS X 10.5 (Leopard). Specific steps for creating a database in MySQL are provided below.
-
Click to close the wizard.
Set up a Database:
-
From the navigate to:
RailsDemo/config/database.yml
-
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
-
Create the RailsDemo_development database:
If your Database Type is either or , 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:
-
Open the
New Rails Resource Wizard
-
Choose "RailsDemo" in the Project dropdown.
-
Name the model:
post
Next, create the attributes for the post model.
-
Type
title
in the Name column. By default it is a string type.
Click in the Required field to open the .
Check "Enabled".
Click in the On field and select "save".
Type
"must be entered to save this post." in the Message field.
Click .
-
Click 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 .
Check "Enabled".
Click in the On field and select "save".
Type
"must be entered to save this post." in the Message field.
Click .
-
Click to add another attribute.
Type "date" in the Name column.
Click in the type column and change the type to datetime.
-
Ensure that is checked.
Ensure that is checked.
-
Click .
-
3rdRail creates the model and controller, and opens the .
The shows outbound and inbound dependencies.
The shows the Rails code and
hyperlinks to the generated files.
Browse in the to see all the elements of the Rails project.
Run the Application:
-
Click the icon from the main
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
.
|
-
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.
-
You can exit the application by pressing the Stop button located in the bottom right of the view
frame.
CodeGear brand
and product names are service marks, trademarks or registered trademarks of Borland Software
Corporation in the United States and other countries.