RubyMine 2024.3 Help

Tutorial: Run a Sinatra application

Sinatra is a library for creating web applications. RubyMine allows you to run a Sinatra application directly as a Ruby script or by using the dedicated Rack run/debug configuration if you are using the rackup tool.

In this tutorial, we'll show you how to run the sample Sinatra application in RubyMine directly as a Ruby script, how to run the application by using the rackup tool, and how to configure additional running options using run/debug configurations.

Prerequisites

Before running the Sinatra application, make sure that the following prerequisites are met:

  • The 'sinatra' and 'rack' gems are installed to the project SDK.

  • The required web server gem (for example, 'thin' or 'puma') is installed to the project SDK.

Run an application as a Ruby script

Run an application

To run a Sinatra application as a Ruby script, follow the steps below:

  1. Press Ctrl twice to invoke the Run Anything popup.

  2. Type the following command in the popup and press Enter.

    ruby app.rb

    If necessary, you can specify the required command-line options and script arguments. For example, to run the application with the Puma server, use the following command:

    ruby app.rb -s Puma

    In this case, the -s Puma command part will be passed as Script arguments to the created Ruby configuration.

  3. Wait until RubyMine starts the application. The Run tool window shows the application's output.

Configure running options

After you run an application as a Ruby script, RubyMine automatically creates the Ruby run/debug configuration. You can customize it to pass additional options.

  1. Select Run | Edit Configurations from the main menu.

  2. In the opened Run/Debug Configurations dialog, select the created ruby app.rb configuration in the Ruby group, and pass the required running options in the Script arguments field. For example, to use the Puma server for this configuration, specify the following value:

    -s Puma
  3. Click OK to save the configuration.

Run the application with 'config.ru'

To run the Sinatra application that uses config.ru file, follow the steps below:

  1. Open the Project view Alt+1.

  2. Right-click the config.ru and select Run 'config.ru'.

  3. Wait until RubyMine starts the application. The Run tool window shows the application's output.

See Run Rack applications to learn more about running Rack applications.

Last modified: 11 February 2024