You must do three things to get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows:
- set BetterErrors.editor
- build a batch file to reformat the path that better_errors supplies into a Windows file path
- make a registry key to handle the protocol 'subl'
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
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
rem fetch the command. it is the first argument
set dest=%1
rem convert %3A to colons
set dest=!dest:%%3A=:!
rem convert %2F to backslashes
set dest=!dest:%%2F=\!
rem convert &line to colon
set dest=!dest:^&line=:!
rem remove equals sign with a "while" loop
rem equals signs are a pain to remove from strings...
set str=!dest!
:LoopStart
REM Do something
set str=!str:~1!
set char=!str!
set char=!char:~0,1!
IF !char!=== GOTO DoNotConcatenate
IF !char!==^" GOTO DoNotConcatenate
set newstr=!newstr!!char!
:DoNotConcatenate
REM Break from the loop if a condition is met
IF !char!==^" GOTO LoopEnd
REM Iterate through the loop once more if the condition wasn't met
GOTO LoopStart
:LoopEnd
rem trim first 23 characters (subl://open/?urlfile://)
set dest=!newstr:~23!
start "" %EXECUTABLE% "!dest!"
Save this file wherever you please. We shall reference it in the next step.
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.
This seems to work nicely, thanks!
Just one thing to be aware of: copying the batch file from here will include indentation, and won't work as-is. Be sure to remove the indentation before saving the file.