How do I start building an application using Ruby on Rails?
The following article explains how to start building an application using Ruby on Rails. It contains information about creating the Rails application, configuring a database, and using scaffolding to link the database to the application. The example used below is the beginning steps for creating a blog using Ruby on Rails.
To create the Rails application, please follow these steps:
- Log into the Linux Web server via Secure Shell (SSH).
- Change to the root folder using the following command:
cd
- Create the application using the following command:
rails blog
- Link this folder to the htdocs folder using the following command:
ln -s ~/blog/public/ ~/htdocs/blog
Note: The application cannot be in the htdocs folder.
The application has been created and is now visible in a Web browser, http://domainname.com/blog/
To link the application to the database, please follow these steps:
- Change to the application folder using the following command:
cd blog/
- Edit the database.yml file using the following command:
pico config/database.yml
- Replace the existing information with the following:
- Save and exit the file.
login: &login
adapter: mysql
host: mysql server
username: username
password: password
development:
database: database name
<<: *login
test:
database: NOT_TESTING
<<: *login
production:
database: database name
<<: *login
The application will now use the database specified in the config file.
To setup the tables in your database, please follow these steps:
- Create a migration to be used to track changes to the database schema using the following command:
./script/generate migration InitialSchema
- Edit the schema that was created using the following command:
pico db/migrate/001_initial_schema.rb
- Between def self.up and end, enter the information found here.
- Save and exit the file.
- Run the migration to setup the tables in the database using the following command:
rake db:migrate
To create scaffolding for the application, please follow these steps:
- Run the following command:
ruby script/generate scaffold post
The blog should be visible using at the following location, http://domainname.com/blog/posts.




