更好的错误宝石无法在本地浏览器中工作,看不到任何错误 [英] Better Errors Gem not working in local browser, no errors visible
问题描述
我将更好的错误"(Better Errors)gem添加到了我的gemfile中,如下面的gemfile所示,然后捆绑运行并看到了Using better_errors 1.1.0
并重新启动了我的服务器几次.我观看了有关如何安装的Railscast情节.过去安装任何其他gem都没有问题(我是编程新手).我阅读了文档,并且已经检查过此内容:
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.
任何有关如何使这种宝石起作用的想法将不胜感激!这是我的gemfile:
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-您在虚拟机上吗?更好的错误有时无法与VM很好地配合.
Valerie -- are you on a virtual machine? Better errors can sometimes not work well with VMs.
我找到的解决方法是:
首先,在应用程序的config/environments/development.rb
(在configure do
内部的任意位置)中,添加:
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']
然后,您需要定义该环境变量.通过启动浏览器,单击旧的错误页面(只需在控制器中放置raise
或类似内容),然后在错误页面的显示环境转储"部分中找到"REMOTE_ADDR",即可找到您的远程IP.然后复制该IP并将其设置为ENV变量(在您的.env
或application.yml
文件中,或放置在其中的任何位置).
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?
这篇关于更好的错误宝石无法在本地浏览器中工作,看不到任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!