How To Use better_errors in Padrino

Dec 18, 2017Ryan Burnette

The development and debugging cycle is much more efficient when developing in Padrino when the addition of the better_errors Gem. The provided documentation won't get better_errors working for you with the installation snippets.

To get the most out of better_errors, two additional items must be added to the Gemfile. I put them in a development group, but you don't have to.

# Gemfile
group :development do
  gem "better_errors"
  gem "binding_of_caller"
end

In config/boot.rb, require better_errors and hook up the Rack Middleman.

# config/boot.rb, after Bundler.require(:default, RACK_ENV)
if Padrino.env == :development
  require 'better_errors'
  Padrino::Application.use BetterErrors::Middleware
  BetterErrors.application_root = PADRINO_ROOT
  BetterErrors.logger = Padrino.logger
end

Cross-Site Request Forgery protection must be disabled in the development environment. Otherwise, better_errors won't work properly. Many functions of better_errors make Ajax requests to a dedicated endpoint that's mounted in your app.

# config/apps.rb
set :protect_from_csrf, !(Padrino.env == :development)

Fork and Star on Github Gist.

Blog Index