RubyMine 2016.2 Help

Create and Run Your First Project

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:

  • Ruby SDK is downloaded and installed on your machine. Refer to this page for details.

Creating your first Rails application

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

To create your first Rails application, follow these steps

  1. Create a new project. To do that, choose File | New Project on the main menu. In the Create New Project dialog box, do the following:
    • In the left-hand pane, select project type Rails Application
    • Specify the project location
    • Select Ruby SDK and Rails version
    rm_createProject
  2. 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

Exploring the project structure

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

Running the server

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 on the main toolbar:

rubySampleRailsApp5

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

rubySampleRailsApp5a

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

Populating your application

Next, let's populate the Rails application.
  1. Create a controller. To do that, press Ctrl+Alt+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

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

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

Observing results

In the view file, add some meaningful contents.

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

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 Create new project 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

Last modified: 21 July 2016