【发布时间】:2016-04-16 23:28:35
【问题描述】:
我正在关注rails tutorial book 并在学习教程时使用c9.io Web IDE。在处理我的示例应用程序时,我注意到在开发模式下页面上没有显示异常。此外,log/development.log 也没有记录异常堆栈跟踪。这种困境让我很难调试代码中的错误。
development.log 中的错误
Completed 500 Internal Server Error in 116ms (ActiveRecord: 2.3ms)
我已经尝试/研究过的内容
-
config.log_level = :debug(在 config/environments/development.rb 中) config.consider_all_requests_local = true- this
- that
- the other
config/environments/development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.log_level = :debug
end
请记住,我不对试图为抛出的异常找到解决方案的答案感兴趣。我只是希望启用异常堆栈跟踪,以便我可以自己调试问题。
2017 年 2 月 25 日编辑
宝石文件
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.36.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '3.1.0'
end
【问题讨论】:
-
您使用的是哪台服务器以及如何运行它?
-
它在开发中使用 WEBrick。我正在使用
rails s -b $IP -p $PORT运行它(c9.io 托管环境中需要$IP和$PORT。请参阅:link)。 -
您找到解决方案了吗?我实际上遇到了同样的问题,不知道如何解决它
-
此行为表明您可能正在生产模式下运行您的应用程序。你确定你在
developmentenv 中运行你的服务器吗? c9 IDE 中的输出选项卡应该是这样的:Rails 4.2.5 application starting in development on http://0.0.0.0:8080- 你能确认一下吗?我刚刚在 c9 上成功设置了一个最小的 rails 应用程序,它显示异常正常 - 请参阅 so-36670968-borama.c9users.io 。另外,当您意识到未显示异常时,您是在 Rails 教程的哪一点?能否提供具体教程部分的链接? -
是的,开发模式。 $rails s => 引导 Puma => Rails 5.0.2 应用程序开始在 localhost:3000 上开发 => 运行
rails server -h以获得更多启动选项 Puma 从单一模式开始... * 版本 3.8.2 (ruby 2.3.1- p112),代号:Sassy Salamander * 最小线程:5,最大线程:5 * 环境:开发 * 监听 tcp://localhost:3000
标签: ruby-on-rails ruby-on-rails-4 exception