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
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.
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