# Debug a script in Rails context

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

The [Rails runner](https://guides.rubyonrails.org/command_line.html#rails-runner) allows you to run Ruby code in the Rails context non-interactively. In RubyMine, you can run and debug project or [scratch](scratches.html) Ruby scripts in the Rails context. In this tutorial, we'll show you how to debug a project Ruby script.

For example, your project contains the Ruby script you want to debug at the following path: `lib/script.rb`. Before debugging, you need to create the Ruby run/debug configuration for running this script using the Rails runner.

> **Note:**
> Before performing the procedure, make sure you [installed the gems](debugging-code.html) required for debugging.

Procedure: Create the run/debug configuration

1. Right-click the `lib/script.rb` file in the editor and select Modify Run Configuration.

![Create the Ruby configuration](https://resources.jetbrains.com/help/img/idea/2026.3/rm_rails_runner_create_config.png)

2. In the Create Run Configuration dialog, specify the following settings:

![Configuration settings](https://resources.jetbrains.com/help/img/idea/2026.3/rm_rails_runner_create_config_settings.png)

* Name: Enter the run/debug configuration name, for example, Rails runner.

* Enable the Execute in the context of Rails option to run the script in the Rails context.

Click OK.

Procedure: Debug the script

To debug the newly created rails runner configuration, do the following:

1. Set a [breakpoint](using-breakpoints.html) in the `lib/script.rb` file.

2. Press `Ctrl` (Windows), `Ctrl` (macOS), `Ctrl` (IntelliJ IDEA Classic (macOS)), `Ctrl` (macOS System Shortcuts), `Ctrl` (XWin), `Ctrl` (GNOME), `Ctrl` (KDE), `Ctrl` (Emacs), `Ctrl` (Sublime Text), `Ctrl` (Sublime Text (macOS)), `Ctrl` (Visual Studio), `Ctrl` (Visual Studio (macOS)), `Ctrl` (TextMate), `Ctrl` (NetBeans), `Ctrl` (Eclipse), `Ctrl` (Eclipse (macOS)) twice and type the [created configuration](#create_config) name in the popup: `Rails runner`.

3. Press and hold down the `Shift` (Windows), `Shift` (macOS), `Shift` (IntelliJ IDEA Classic (macOS)), `Shift` (macOS System Shortcuts), `Shift` (XWin), `Shift` (GNOME), `Shift` (KDE), `Shift` (Emacs), `Shift` (Sublime Text), `Shift` (Sublime Text (macOS)), `Shift` (Visual Studio), `Shift` (Visual Studio (macOS)), `Shift` (TextMate), `Shift` (NetBeans), `Shift` (Eclipse), `Shift` (Eclipse (macOS)) key (the dialog title changes to Debug) and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)). RubyMine will suspend the script execution before the breakpoint.

![Rails runner debug](https://resources.jetbrains.com/help/img/idea/2026.3/rm_rails_runner_debug.png)

