hostmysite.com

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:

  1. Log into the Linux Web server via Secure Shell (SSH).
  2. Change to the root folder using the following command: cd Change to the root folder.
  3. Note: The application cannot be in the htdocs folder.

  4. Create the application using the following command: rails blog Create the application.
  5. Link this folder to the htdocs folder using the following command:
    ln -s ~/blog/public/ ~/htdocs/blog Link this folder to 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:

  1. Change to the application folder using the following command: cd blog/ Change to the application folder.
  2. Edit the database.yml file using the following command: pico config/database.yml Edit the database.yml file.
  3. Replace the existing information with the following:
  4. 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
  5. Save and exit the file.

The application will now use the database specified in the config file.

To setup the tables in your database, please follow these steps:

  1. Create a migration to be used to track changes to the database schema using the following command:
    ./script/generate migration InitialSchema Create a migration to track database changes.
  2. Edit the schema that was created using the following command:
    pico db/migrate/001_initial_schema.rb Edit the schema.
  3. Between def self.up and end, enter the information found here. Enter the information.
  4. Save and exit the file.
  5. Run the migration to setup the tables in the database using the following command:
    rake db:migrate Run the migration.

To create scaffolding for the application, please follow these steps:

  1. Run the following command: ruby script/generate scaffold post Create the scaffolding.

The blog should be visible using at the following location, http://domainname.com/blog/posts.

Additional Support Topics

Search Support Articles