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:
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 http://rubyonrails.org/download for details.
The procedure below describes creating a simple project on Windows platform.
- Create a new project. To do that, choose Create New Project dialog box, specify the project name HelloWorld,
select project type Rails Application, and click OK.
Rails Application Settings dialog box opens:
main menu. In the
- In the Rails Application Settings dialog box, do the
- Specify the Ruby interpreter to be used in your project: accept the suggested interpreter
version, or choose another one.
To do that, click , and choose ruby.exe in the
Select Ruby Interpreter Path dialog box:
- Select Rails version. If Rails gem for this interpreter version is not detected, click
RubyMine downloads the Rails gems list. Then, in the Install Rails Gem
dialog box, select the version be installed:
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:
You can see that RubyMine has taken care of the proper application structure:
- Specify the Ruby interpreter to be used in your project: accept the suggested interpreter version, or choose another one. To do that, click , and choose ruby.exe in the Select Ruby Interpreter Path dialog box:
- Explore the project structure. To do that, switch to the Rails view:
click the title bar of the
Project tool window, and select Rails:
- 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 on the
The Console tab of the Run tool window shows the URL where the Rails application starts. Copy this address to the clipboard:
After that, to make sure the settings are correct and the Rails server works properly, preview results in the browser.
- Next, let's populate the Rails application.
- 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:
In the Add New Controller dialog box, specify the name and optional location of the controller, and add the necessary actions:
So doing, RubyMine runs generate script and creates the stub controller and the corresponding views.
- 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:
- 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
open the corresponding view file:
- 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
and then select the desired browser from the pop-up menu of the supported browsers:
The result displays in the selected browser:
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.