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: cdChange to the root folder.
  3. Note: The application cannot be in the htdocs folder.

  4. Create the application using the following command: rails blogCreate the application.
  5. Link this folder to the htdocs folder using the following command:
    ln -s ~/blog/public/ ~/htdocs/blogLink 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.ymlEdit the database.yml file.
  3. Replace the existing information with the following:
    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
  4. Save and exit the file.
  5. Edit the environment.rb file using the following command: pico config/environment.rbEdit the environment.rb file
  6. Add the following line under '# config.gem "aws-s3", :lib => "aws/s3":" config.action_controller.relative_url_root = "/blog"
  7. 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 InitialSchemaCreate a migration to track database changes.
  2. Edit the schema that was created using the following command:
    pico db/migrate/001_initial_schema.rbEdit 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:migrateRun the migration.

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

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

To create the dispatcher, please follow these steps:

  1. Change to the blog/public folder using the following command: cd blog/publicChange directory to blog/public.
  2. Create a new text file named '.htaccess' using the following command: pico .htaccessCreate a .htaccess file
  3. Insert the text found here into the file.
  4. Save and exit the file.
  5. Create a new text file named 'dispatch.fcgi' using the following command: pico dispatch.fcgiCreate a dispatch.fcgi file
  6. Insert the text found here into the file.
  7. Save and exit the file.
  8. Create a new text file named 'dispatch.rb' using the following command: pico dispatch.rbCreate a dispatch.rb file
  9. Insert the text found here into the file.
  10. Save and exit the file.

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