Skip to content
MOZGIII edited this page Oct 19, 2015 · 23 revisions

Security

See the Security page.

View last error

Better Errors saves the most recent error page displayed at /__better_errors.

This can be handy if you aren't able to see the error page served up when the exception occurred, eg. if the errored request was an AJAX or curl request.

Adjusting the project base path for the editor link

If your Rails app is running from a shared folder in a VM, the path to your source files from Rails' perspective could be different to the path seen by your editor.

You can adjust the path used to generate open-in-editor links by putting this snippet of code in an initializer:

if defined?(BetterErrors)
  BetterErrors.editor = proc { |full_path, line|
    full_path = full_path.sub(Rails.root.to_s, your_local_path)
    "my-editor://open?url=file://#{full_path}&line=#{line}"
  }
end

If you're working on a project with other developers, your base path may be not be the same as the other developers'.

You can use an environment variable to work around this by replacing your_local_path in the snippet above with ENV["BETTER_ERRORS_PROJECT_PATH"] and starting your Rails server like this:

$ BETTER_ERRORS_PROJECT_PATH=/path/to/your/app rails server

Opening files in RubyMine

RubyMine on OS X:

See http://www.railsonmaui.com/tips/rubymine/. Simply, in your Gemfile:

group :development do
  gem 'better_errors'
end

And in development.rb

 BetterErrors.editor='x-mine://open?file=%{file}&line=%{line}' if defined? BetterErrors

Opening files in iTerm+vim

Users of iTerm and vim (cli version) on OS X can follow the instructions provided at https://github.com/phallstrom/urlscheme_vim_in_iterm to configure Better Errors to open files in a new iTerm session using vim.

Opening files in emacs via firefox

You need to register the emacs:// protocol in firefox. Also, ffox will pass a lot of junk to the command, here's a suggestion for your bin/ folder: https://gist.github.com/nofxx/6987409

Opening files in sublimetext

Install a sublimetext handler: https://github.com/dhoulb/subl

Set this in .bashrc:

export EDITOR=subl

If you use Pow and it doesn't detect that, just add the same line to .powconfig

You can also set this per project, in initializer (config/initializers/better_config.rb):

BetterErrors.editor = :sublime if defined? BetterErrors

Better Errors with Vagrant

To open the files when using Vagrant use the vagrant-host-path gem.

The complete example will look like this:

# Allow usage on Vagrant
if defined?(BetterErrors)
  # Opening files
  BetterErrors.editor = proc { |full_path, line|
    full_path = full_path.sub(Rails.root.to_s, ENV["VAGRANT_HOST_PATH"])
    "subl://open?url=file://#{full_path}&line=#{line}"
  }

  # Allowing host
  host = ENV["SSH_CLIENT"] ? ENV["SSH_CLIENT"].match(/\A([^\s]*)/)[1] : nil
  BetterErrors::Middleware.allow_ip! host if [:development, :test].member?(Rails.env.to_sym) && host
end