17

I added the Better Errors gem to my gemfile like as seen in my gemfile below, and ran bundle and saw Using better_errors 1.1.0 and restarted my server several times. I watched the railscast episode on how to install it. I’ve never had a problem installing any other gem in the past (I'm new to programming). I read the documentation and I already checked for this:

Note: If you discover that Better Errors isn't working - particularly after upgrading from version 0.5.0 or less - be sure to set config.consider_all_requests_local = true in config/environments/development.rb.

Any ideas on how to get this gem working would be much appreciated! Here is my gemfile:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'

group :development, :test do

  gem 'rspec-rails'
  gem 'capybara'
end


# Use sqlite3 as the database for Active Record
 group :production do
   gem 'pg'
   gem 'rails_12factor'
 end

 group :development do
   gem 'sqlite3'
   gem 'better_errors'
 end

 gem 'bootstrap-sass', '~> 3.1.1'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
Valerie Mettler
  • 475
  • 4
  • 16

6 Answers6

30

With Vagrant, add this to your app's config/environments/development.rb (anywhere inside the configure block):

BetterErrors::Middleware.allow_ip! "0.0.0.0/0"

Then restart your server.

(This is just a slight variation on Sasha's solution.)

DO NOT add this to your production environment!

Matt Collins
  • 301
  • 3
  • 4
21

Valerie -- are you on a virtual machine? Better errors can sometimes not work well with VMs.

The solution I've found is this:

First, in your app's config/environments/development.rb (anywhere inside the configure do), add:

BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']

Then you need to define that environment variable. Find your remote IP by firing up a browser, hitting the old error page (just throw a raise in a controller or something), and finding the "REMOTE_ADDR" in the error page's "Show env dump" section. Then copy that IP and set it as an ENV variable (in your .env or application.yml file, or wherever you keep those).

Note -- DO NOT add that to production. It's unnecessary at best (Better Errors should only be run/included in development -- as you've ensured above).

Then restart your server. Any chance that fixes it?

Sasha
  • 6,224
  • 10
  • 55
  • 102
  • Yes, I'm using vagrant. I understand how to do all of the steps you mentioned, except the last step (setting the IP as an ENV variable). I don't have an .env file, so I would be putting it in my application.yml file. Do I just simple type ENV['Whatever the IP is'] into that file? Or is it ENV['TRUSTED_IP']= "whatever the ip is" Thanks! – Valerie Mettler Oct 02 '14 at 21:33
  • 1
    You follow the pattern you've already got in there, if there are variables in there already -- those are all ENV vars. Because it's a YAML file, that will be in `KEY: value` format. (Say `DEVISE_TOKEN: iamatoken12345`. So, `TRUSTED_IP: 1234567`). You can test that it's worked by booting up `rails console` after making that change and seeing what the value of `ENV[TRUSTED_IP]` is. Indentation is important in YAML, so make sure that your indentation is even (in this case, that the key isn't indented at all). – Sasha Oct 02 '14 at 21:39
  • Just to clarify -- there is no canonical way to set ENV variables. Some people put them in a `.env` file, which can be formatted however they like, and pull them out and assign them to the global ENV constant with some Ruby that's run when the application boots. Other times they're stored in YAML and pulled out using a gem, etc. But the trick is just to pick a way and follow that pattern. They're all relatively equivalent. – Sasha Oct 02 '14 at 21:42
  • Typo above SO won't let me edit: It's `ENV['TRUSTED_IP']` (which is how you typed it anyway), not my version without the quotes above. – Sasha Oct 02 '14 at 21:48
3

in addition for all better you need to add this to your config/environments/development.rb:

BetterErrors::Middleware.allow_ip! "TRUSTED_IP" where "trusted_ip" is "REMOTE_ADDR" in default error page for me it's 10.0.2.2

Terry Sahaidak
  • 513
  • 1
  • 5
  • 16
2

In the file app/config/environments/development.rb do you have this line present in the code ?

# Show full error reports and disable caching.
config.consider_all_requests_local = true
Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
user1854802
  • 388
  • 3
  • 14
  • the only thing I could think of was checking which version of better_errors is installed. I know from my gemfile - group :development do gem 'debugger' gem 'rack-mini-profiler' # performance testing gem 'better_errors', '~> 2.0.0' end. – user1854802 Oct 02 '14 at 02:33
  • 1
    Thanks @user1854802, I updated the version to 2.0.0 but still no luck with getting better errors to show up! Let me know if you have any other thoughts later on! – Valerie Mettler Oct 02 '14 at 04:36
0

I am running vagrant, rails 5 and ruby 2.3 and I added the below to my config/environments/development.rb and got it working.

  # Allow usage of better_errors on Vagrant
  BetterErrors::Middleware.allow_ip! "10.0.2.2"

  # Show full error reports and disable caching.
  config.consider_all_requests_local = true

Same answers as above but just wanted to confirm it for anyone running the rails 5 beta.

Jay Killeen
  • 2,832
  • 6
  • 39
  • 66
0

Old question but in case this can help anyone. I just ran into the same issue running this on my localhost: Better errors was installed and configured but I received no helpful errors.

Issue was easily solved by running bundle update.

This updated Using better_errors 2.9.1 (was 2.4.0) and now I get better errors.

bitfidget
  • 357
  • 2
  • 3
  • 12