public

Get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows

  • Download Gist
Using-sublime-w-better-errors-gem.md
Markdown

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.

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.