editor_opener
Open source files in your editor directly from Rails error pages. This gem adds clickable links to file paths in Rails error pages, allowing you to instantly open files at the exact line where errors occur.
Features
- 🔥 Works with Rails 7.1+
- 🔗 Clickable file links in Rails error pages
- 📝 Multiple editor support - Works with 13+ popular editors
- 🎯 Precise line targeting - Opens files at the exact error line
- 🔧 Easy configuration - Set via initializer or environment variable
- 🚀 Zero configuration - Works out of the box with
EDITOR
environment variable - 📱 Custom URL schemes - Uses editor-specific protocols for seamless integration
Installation
Add this line to your application's Gemfile:
group :development do
gem "editor_opener"
end
And then execute:
$ bundle install
Configuration
Option 1: Generate and configure initializer (Recommended)
$ rails generate editor_opener:install
This creates config/initializers/editor_opener.rb
with all supported editors listed as comments.
Edit the initializer to set your preferred editor:
EditorOpener.setup do |config|
config.editor = :cursor # or any other supported editor
end
Option 2: Environment variable
Set the EDITOR
environment variable:
export EDITOR=cursor # for Cursor
export EDITOR=atom # for Atom
export EDITOR=subl # for Sublime Text
Usage
- Install and configure the gem (see above)
- Restart your Rails server
- Trigger an error in your Rails application
- Click the edit icons (✏️) or line numbers in the error page to open files in your editor
The gem automatically detects error traces from:
- Application code
- Gem files
- Direct file paths
Supported Editors
The gem supports the following editors with their respective symbols:
Editor | Symbols | Protocol |
---|---|---|
Atom | :atom |
atom:// |
Cursor | :cursor |
cursor:// |
Emacs |
:emacs , :emacsclient
|
emacs:// |
IntelliJ IDEA | :idea |
idea:// |
MacVim |
:macvim , :mvim
|
mvim:// |
Nova | :nova |
nova:// |
RubyMine | :rubymine |
x-mine:// |
Sublime Text |
:sublime , :subl , :st
|
subl:// |
TextMate |
:textmate , :txmt , :tm
|
txmt:// |
Visual Studio Code |
:vscode , :code
|
vscode:// |
VSCodium |
:vscodium , :codium
|
vscodium:// |
Windsurf | :windsurf |
windsurf:// |
Zed | :zed |
zed:// |
Examples
Basic Configuration
# config/initializers/editor_opener.rb
EditorOpener.setup do |config|
config.editor = :cursor
end
Environment Variable
# In your shell profile (~/.bashrc, ~/.zshrc, etc.)
export EDITOR=cursor
# Or in your .env file (if using dotenv)
EDITOR=cursor
Multiple Environments
# config/initializers/editor_opener.rb
EditorOpener.setup do |config|
config.editor = Rails.env.development? ? :cursor : nil
end
How It Works
- Error Detection: The gem overrides Rails error pages
- Trace Parsing: Extracts file paths and line numbers from stack traces
- Editor Detection: Matches configured editor with supported protocols
- URL Generation: Creates editor-specific URLs for file opening
- Link Enhancement: Adds clickable links to error page templates
Troubleshooting
Editor doesn't open files
- Check editor configuration: Ensure your editor symbol is correct
- Verify protocol support: Make sure your editor supports URL protocols
-
Test environment variable: Try setting
EDITOR
environment variable - Restart Rails server: Configuration changes require server restart
Links don't appear
- Check gem is loaded: Ensure gem is in development group
- Verify Rails environment: Gem typically only works in development
- Test with simple error: Create a basic error to test functionality
Development
After checking out the repo, run:
$ bin/setup
$ bin/test
To run tests:
$ bin/test
$ bin/rubocop
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/igorkasyanchuk/editor_opener.
- Fork the project
- Create your feature branch (
git checkout -b my-new-feature
) - Make your changes
- Add tests for your changes
- Ensure all tests pass (
bin/test
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
TODO
-
verify it works with old Rails versions (test with 7.1.0 and it works, for older versions it doesn't work) possible fix:
# in railtie.rb if defined?(ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS) ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS.unshift(path) else module X def initialize(assigns) paths = [RESCUES_TEMPLATE_PATH] lookup_context = ActionView::LookupContext.new(paths, path) super(lookup_context, assigns, nil) end end ActionDispatch::DebugView.prepend(X)
But something is wrong in the views. Maybe we need to support older views, and create a new copy of them? Also, you don't see the full exception, maybe this setting
config.action_dispatch.show_exceptions
can help, or capture exception with begin/rescue and print in the console? -
more tests
-
support for more error pages?
-
support for more editors
License
The gem is available as open source under the terms of the MIT License.
Credits
Created by Igor Kasyanchuk.
Related Projects
- better_errors - Better error pages for Rails
- web-console - Rails console in your browser