RubyMine 7.0.0 Web Help

To get more familiar with RubyMine it is recommended that you create from scratch your first project with the very basic functionality.

In this section:

Prerequisite

Creating a living Web application that enables you to view results in a browser of your choice requires the following prerequisite to be fulfilled:

To create your first Rails application, follow these steps

The procedure below describes creating a simple project on Windows platform.

  1. Create a new project. To do that, choose File | New Project on the main menu. In the Create New Project dialog box, specify the project name HelloWorld, select project type Rails Application, and click OK.

    Rails Application Settings dialog box opens:

    ruby_newRailsAppDialog.png

  2. In the Rails Application Settings dialog box, do the following:
    • Specify the Ruby interpreter to be used in your project: accept the suggested interpreter version, or choose another one. To do that, click browseButton, and choose ruby.exe in the Select Ruby Interpreter Path dialog box:

      ruby_selectInterpreter

    • Select Rails version. If Rails gem for this interpreter version is not detected, click browseButton. RubyMine downloads the Rails gems list. Then, in the Install Rails Gem dialog box, select the version be installed:

      ruby_installRailsGem

      Do not forget to select the check box Automatically install dependent gems.

      Click Install. RubyMine installs the selected version, and the dependent gems.

    • Click OK.

    RubyMine creates stub Rails application, which is reflected in the Run tool window:

    ruby_RailsAppCreated

    You can see that RubyMine has taken care of the proper application structure:

    rubySampleRailsApp1.png

  3. Explore the project structure. To do that, switch to the Rails view: click the title bar of the Project tool window, and select Rails:

    rubySampleRailsApp2.png

  4. If you want to see how your application works, launch the Web server. To do that, choose the Development run/debug configuration from the Run/Debug Configuration drop-down list, and then click the run button runBuild.gif on the main toolbar:

    rubySampleRailsApp5.png

    The Console tab of the Run tool window shows the URL where the Rails application starts. Copy this address to the clipboard:

    rubySampleRailsApp5a.png

    After that, to make sure the settings are correct and the Rails server works properly, preview results in the browser.

  5. Next, let's populate the Rails application.
    1. Create a controller. To do that, press Ctrl+Alt+GCtrl+Alt+GCtrl+Alt+GCtrl+Alt+GCtrl+Alt+GCtrl+Alt+GCtrl+Alt+GCtrl+Alt+GAlt+GAlt Command GAlt GAlt Command GAlt G, and in the pop-up window start typing the desired generator name. In our case, this is controller:

      rubySampleRailsApp7

      In the Add New Controller dialog box, specify the name and optional location of the controller, and add the necessary actions:

      rubySampleRailsApp3.png

    So doing, RubyMine runs generate script and creates the stub controller and the corresponding views.

  6. Open the controller in the editor, and use the gutter icons to navigate to a view associated with an action. For example, click the gutter icon to the left of the say action to open the corresponding view file:

    rubySampleRailsApp4.png

  7. In the view file, add some meaningful contents.
  8. Observe results in a browser of your choice. To do that, hover your mouse pointer over the view code, and then select the desired browser from the pop-up menu of the supported browsers:

    rubySampleRailsApp6.png

    The result displays in the selected browser:

    rubySampleRailsApp8

Important note on using databases

In the real-life applications, using databases is required. In this case it is important that one of the supported database servers should be installed, the daemon should be running and accessible to your machine.

Make sure that the required databases are available. First, launch your preferred database server. For example, in the Windows environment, you can launch the MySQL daemon from the command line, by typing mysql.exe. Note that if you choose sqlite3, no additional actions are required.

In the Rails Application Settings dialog box, you have to select the check box Preconfigure for selected database, and choose the desired database.

When your Rails application is created, you have to run Rake task db:create:all. Thus, a database required by your Rails application, as it is described in the database.yml file, will be created.

After updating the model structure of your application, run Rake task db:migrate.

See Also

Concepts:

Procedures:

Reference:

Getting Started:

Web Resources: