RubyMine 2019.2 Help

Creating Rails Application Elements

RubyMine helps you populate Rails applications with the stubs of all the required elements: controllers, views, models, and so on. You can launch Rails generators in several ways:

  • Press Ctrl twice and start typing a required command or its part (for example, rails g controller). Then, select this command from the suggestion list and press Enter.

  • Use the Tools | Run Rails Generator menu command.

  • Go to File | New (Alt+Insert) and select Run Rails Generator.

In this topic, we’ll show you several examples on how to create Rails application elements.

Create controllers and actions

To generate a controller and optionally its actions, do the following:

  1. Press Ctrl twice and start typing rails g controller. Select rails g controller and press Enter.

  2. In the invoked Add New Controller dialog, specify the controller name. Optionally, add the action names separated by spaces (for example, new create). Click OK.

    Add New Controller
  3. RubyMine generates required files (a controller, view, and other) and displays output in the Run tool window.

    Run tool window

    You can click any file to quickly open it in the editor.

Create views from actions

You can create a view for a specified controller action right in the editor. To do this:

  1. Open a controller file in the editor.

  2. Locate the desired action and click the View for action icon in the left gutter of the editor.

    Create view from action
  3. If a view associated with the method exists, it is opened in the editor. If a view doesn't exist, RubyMine suggests creating a new one.

    Go to view

    Specify the name of the view file and click OK. Note that you can create ERB or Haml view.

Create models

To create a model, perform the following steps:

  1. Press Ctrl twice and start typing rails g model. Select rails g model and press Enter.

  2. In the invoked Add New Model dialog, specify the model name, attributes and its types (for example, Article title:string text:text). Click OK.

    Add New Model
  3. RubyMine generates required files (a model and migration) and displays output in the Run tool window.

    Run tool window

    You can click any file to quickly open it in the editor.

Run migrations

To run a migration, you need to execute a corresponding Rake command:

  1. Press Ctrl twice and start typing rake db:migrate. Select rake db:migrate and press Enter.

  2. In the invoked dialog, you can select the latest or choose the specific migration. Click OK.

    Execute db:migrate
  3. RubyMine executes this migration and displays the created tables in the Run tool window.

    Run tool window
Last modified: 5 August 2019