更好的错误Gem无法在本地浏览器中工作,没有错误可见

我将更好的错误gem添加到我的gemfile中,如下面的gemfile中所示,并运行bundle并看到Using better_errors 1.1.0并重启我的服务器几次。 我看了关于如何安装它的railscast剧集。 我以前从未遇到过安装任何其他gem的问题(我是编程新手)。 我阅读了文档,我已经检查了这个:

 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. 

如何让这个gem工作的任何想法将非常感谢! 这是我的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 – 你在虚拟机上吗? 更好的错误有时可能无法与VM一起使用。

我发现的解决方案是这样的:

首先,在你的应用程序的config/environments/development.rb (在configure do任何地方),添加:

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

然后,您需要定义该环境变量。 通过启动浏览器找到您的远程IP,点击旧的错误页面(只是在控制器或其他东西中引发raise ),并在错误页面的“显示环境转储”部分中找到“REMOTE_ADDR”。 然后复制该IP并将其设置为ENV变量(在.envapplication.yml文件中,或者保存它们的任何位置)。

注意 – 请勿将其添加到生产中。 这是不必要的(更好的错误应该只在开发中运行/包含 – 正如你已经确定的那样)。

然后重启服务器。 有机会修复它吗?

使用Vagrant,将其添加到应用程序的config/environments/development.rbconfigure块内的任何位置):

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

然后重启服务器。

(这只是Sasha解决方案的一个细微变化。)

请勿将其添加到您的生产环境中!

除此之外,你需要将它添加到你的config/environments/development.rb

BetterErrors::Middleware.allow_ip! "TRUSTED_IP" BetterErrors::Middleware.allow_ip! "TRUSTED_IP" ,其中“trusted_ip”是默认错误页面中的“REMOTE_ADDR”,对于我来说是10.0.2.2

在文件app/config/environments/development.rb ,您是否在代码中显示此行?

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

我正在运行vagrant,rails 5和ruby 2.3,我将以下内容添加到我的config/environments/development.rb并使其正常工作。

  # 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 

与上面相同的答案,但只是想确认任何运行rails 5 beta的人。

Interesting Posts