Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better Errors Gem not working in local browser, no errors visible

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'
like image 718
Valerie Mettler Avatar asked Oct 02 '14 00:10

Valerie Mettler


3 Answers

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!

like image 140
Matt Collins Avatar answered Nov 02 '22 17:11

Matt Collins


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?

like image 21
Sasha Avatar answered Nov 02 '22 17:11

Sasha


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

like image 3
Terry Sahaidak Avatar answered Nov 02 '22 17:11

Terry Sahaidak