IntelliJ IDEA 2023.1 Help

Create and run your first Rails application

This tutorial will show you how to create and run the most simple Rails project in IntelliJ IDEA.

Before starting this tutorial, do the following:

We'll perform all steps using IntelliJ IDEA installed on macOS.

Create a Rails application

To create a Rails application from scratch, do the following:

  1. Run IntelliJ IDEA and click New Project on the Welcome Screen.

  2. In the New Project dialog, select Ruby on Rails on the left pane.

    New project dialog / Ruby on Rails
  3. Provide the following project details:

    • Name: specify the project name.

    • Location: specify the path to the directory in which you want to create the project. By default, the IDE creates a directory with the same name as the project.

    • Ruby SDK: select the required Ruby interpreter installed on your system.

    • Rails: select the Rails version. If the Rails gem is not installed for the selected SDK, expand the Rails Version dropdown and select Install Rails Gem. In the invoked dialog, select the required Rails version and click Install.

    • Project type: select Ruby on Rails as the application type.

    Click Create to continue.

  4. IntelliJ IDEA creates a new Rails application, installs the gem dependencies mentioned in Gemfile, and installs JavaScript dependencies mentioned in the project's package.json file. You can see this process in the Run tool window.

    Generating Rails Application for a project
  5. After installing all dependencies, you can see a project structure in the Project tool window (Alt+1) on the left. On the right, IntelliJ IDEA automatically opens main project files in the editor.

    New Rails Application

    If you have Git installed in your operating system, generating a new Rails application also initializes a Git repository. You can learn how to work with Version control systems in IntelliJ IDEA from the Version control section.

Start a web server

Now we have a functioning Rails application. To see it in action, you need to start a web server. Perform the following steps to do this:

  1. Press Control twice and start typing development.

  2. Select the Development run configuration from the list and press Enter.

    Run Development configuration
  3. IntelliJ IDEA will show the process of preparing the application to run.

    Rails server output
  4. Copy the 0.0.0.0:3000 address used by a web server, insert it to the browser’s address bar and press Enter to see the Rails default information page.

    Rails default page

Create a controller and view

Now let’s create a new page. To do this, you need to create a controller and a view.

  1. Press Control twice and start typing controller. In the invoked list, select rails g controller and press Enter.

    rails g controller
  2. In the invoked Add New Controller dialog, set the controller name to Welcome and add one action called index. Click OK.

    Add New Controller
  3. IntelliJ IDEA will create a controller, view, and several other files. This process will be displayed in the Run tool window. In this window, click the index.html.erb file.

    generate script output
  4. In the opened index.html.erb file, delete all of the existing code in the file, and replace it with the following single line of code:

    <h1>Hello, Rails!</h1>
  5. To see the result, hover your mouse pointer over the view code, and then select the desired browser from the pop-up.

    Show in browser
  6. The index page will be opened in a selected browser.

    Hello Rails
Last modified: 21 June 2023