Skip to content

Instantly share code, notes, and snippets.

@entrity
Last active December 17, 2015 09:08
Show Gist options
  • Save entrity/5584662 to your computer and use it in GitHub Desktop.
Save entrity/5584662 to your computer and use it in GitHub Desktop.
Get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows

You must do three things to get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows:

  1. set BetterErrors.editor
  2. build a batch file to reformat the path that better_errors supplies into a Windows file path
  3. make a registry key to handle the protocol 'subl'

Set BetterErrors.editor

In your rails projects initializes directory, add a single file (call it whatever you want; I called it better_errors.rb) whose contents is:

BetterErrors.editor = :sublime if defined? BetterErrors

Make a batch file

Create a .bat file to reformat the argument supplied by the link on the better_errors page into a Windows file path, and open its file with Sublime Text 2. (When setting your variable EXECUTABLE, set it to the path of your Sublime Text 2 installation.)

@echo off

set EXECUTABLE="C:\Program Files\Sublime Text 2\sublime_text.exe"

setlocal EnableDelayedExpansion

set dest=%1    
set dest=!dest:%%3A=:!
set dest=!dest:%%2F=\!
set dest=%dest:~25%

%EXECUTABLE% "%dest%"

Save this file wherever you please. We shall reference it in the next step.

Make a registry key

Run regedit to open your Windows registry editor. Create the following key:

HKEY_CLASSES_ROOT/
  subl/
    (Default)    "URL:subl Protocol"
    URL Protocol ""
    shell/
      open/
        command/
          (Default) "<.bat filepath>" "%1"

In the key above, <.bat filepath> should be the path of the .bat file you created in step two.

@kurttomlinson
Copy link

Thanks for this! Sometimes it feels like I'm the only one in the world developing Ruby on Rails in Windows. Your solution helped me so much. I improved on it a little bit: https://gist.github.com/kurttomlinson/7503731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment