Getting started rolling with Ruby on Rails in RadRails [edit]

This Help topic gives an overview of how to get started with Ruby on Rails in RadRails.

Contents

Introduction

This Help topic gives an overview of how to start using the RadRails IDE. It describes how to create and test an empty web application and how to create a new controller class for your web application. For more detailed information about performing various development tasks in RadRails, see the individual Help topics on the main RadRails wiki page:

http://aptana.com/docs/index.php/RadRails

Note: This Help topic is based on the Rolling with Ruby on Rails tutorial from ONLamp:

http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1

Instructions

The instructions below will explain how to set up and test a web project for the "Cookbook" database that is used in Setting up the Cookbook database in RadRails.

Creating an empty web application

To create an empty web application in RadRails for your Cookbook project:

  1. In the Ruby Explorer View, right-click inside the view and select New > Rails Project from the context menu. This opens a New Rails Project wizard.
  2. In the Project name field, type Cookbook.
  3. Leave all of the default items checked.
  4. Click the Finish button.

RadRails creates an empty Cookbook project for you, a new server, and launches the server and a browser window.

You should see something similar to the image below if everything was created and configured correctly:

Image:browserLaunch.png

Creating a new controller class

To create a new controller class for your Cookbook project:

  1. Select the Generators tab to go to the Generators View.
  2. Create your controller:
    1. From the drop-down list on the left, select controller.
    2. Choose the create option below the drop-down list.
    3. In the drop-down list on the right, type a name for your test controller (e.g. myTest).
    4. Click the Go button to create the controller.
  3. Test your controller.
    1. In Rails Navigator View, navigate to Cookbook > app > controllers, and open the my_test_controller.rb file.
    2. Copy and paste the index method below and save the my_test_controller.rb file.

      def index
          render :text => "Hello World!"
      end
      

    3. In the Browser preview (from the previous step), change the URL to http://localhost:[port]/my_test and press Enter to refresh the browser. (The name that you append should match the prefix of the controller file that you just edited.)

      Image:helloWorldTest.png

    4. Copy and paste the dilbert method below and save the my_test_controller.rb file. Your file should look like the image below the code sample.

        def dilbert
          render :text => "Wow, that was easy!"
        end
      

      Image:sampleCode.png

    5. In the Browser preview, change the URL to http://localhost:[port]/my_test/dilbert and press Enter to refresh the browser.

      You should see something similar to the image below.

Image:easyTest.png

See Setting up the Cookbook database in RadRails to learn how to set up a sample "Cookbook" database in RadRails.

Related Topics