新手问题 rails 报错"We're sorry, but something went wrong."

58383788 · 2015年05月23日 · 最后由 XixiAndRuby 回复于 2017年12月31日 · 6452 次阅读

大家好,我是一个新人在学习 ror. 从开始做到现在一直都好好的,中间也有过各种报错,自己学会了查看 Log,google+stackoverflow 可以解决。不过昨天碰到的这个问题真是令人蛋碎了.折腾一整天了。还是没有任何办法. 教材用的是安道 ruby on rails tutorial 中文第三版,到第九章第三节,"列出所有用户",即是在首页点击"Users"标签可以查看所创建的所有用户,我的代码和书上保持完全一致. 并且在设立用户的时候,没有采用中文用户名,全是英文用户名。这是报错的页面

运行 rails 的环境背景是 mac os 10.10.3,

gem 列表为

gem 'rails',                '4.2.0'
gem 'bcrypt',               '3.1.7'
gem 'bootstrap-sass'
gem 'sass-rails',           '5.0.0.beta1'
gem 'uglifier',             '2.5.3'
gem 'coffee-rails',         '4.1.0'
gem 'jquery-rails',         '4.0.0.beta2'
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',           '2.11.1'
end

rals -s -e development 下. 终端显示为

Started GET "/users" for ::1 at 2015-05-23 11:05:07 +0800
Processing by UsersController#index as HTML
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  User Load (0.3ms)  SELECT "users".* FROM "users"
  Rendered users/index.html.erb within layouts/application (5.3ms)
Completed 500 Internal Server Error in 13ms

查看 development.log,得到

Started GET "/users" for ::1 at 2015-05-23 11:05:07 +0800
Processing by UsersController#index as HTML
  [1m[36mUser Load (0.2ms)[0m  [1mSELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m  [["id", 1]]
  [1m[35mUser Load (0.3ms)[0m  SELECT "users".* FROM "users"
  Rendered users/index.html.erb within layouts/application (5.3ms)
Completed 500 Internal Server Error in 13ms

请问我的问题出在哪里呢?

看你的后台报错信息,你给的信息太少了

#1 楼 @michael0015 是 Log 中的信息吗?

@58383788 less log/production.log 看,找出 error 的地方,你可能只看到了部分日志。

config/environments/development.rb

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

这样显示错误。

5 楼 已删除

#4 楼 @chenge 呃?能具体一点吗。我不是很懂,要怎样改正呢?

#6 楼 @58383788 很简单。你找到那个文件,照这个修改。然后重启 rails,就会显示错误。

这个答案价值 1000 元,如果都像你那样检查错误,会累死的。

8 楼 已删除

首先建议你把贴出来的 log 删掉。 请你把你的 development.rb 贴出来。有没有按我说的修改?改对了么?那一行本身是有的,一般就是 true/false 开关一下。

Rendered users/index.html.erb within layouts/application (5.5ms)
Completed 500 Internal Server Error in 38ms

检查一下 users/index.html.erb,不过我在开发环境下 500 报错很少见,我一般都是部署之后才出现过 500... 还有楼主 最好把代码贴出来,放 Github 上

补充一下,程序员不是神仙,没人能修复 500 错。

#11 楼 @chenge 抱歉,基础太差了。满脑子雾水.很感谢你的耐心和提醒,我把 Log 删掉了. 我观察了一下 development.rb.你叫我修改的地方其实正是打开的。我补充一些环境和配置的基础吧. 谢谢,确实麻烦了,太新手见笑了

#12 楼 @58383788 你把 development.rb 贴出来吧。每个人都曾经是新手。

比较奇怪,development 情况下怎么会出这个页面? 是部署了吗?

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

  # 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
end

#12 楼 @58383788 请补充下,ruby 版本。 #14 楼 @cqcn1991 我还遇到过换一下 ruby 新版,就出这个的。

#10 楼 @springwq 感谢你的回复,检查过几遍了,和作者的代码没有任何差别,我把项目上传到了 github 上,这是链接https://github.com/58383788/sample_app.git

#15 楼 @58383788

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

我这边还有一行,不过似乎那个跟本案无关。

#16 楼 @chenge 版本为 ruby 2.0.0p643

#16 楼 @chenge ~ ruby -v ruby 2.0.0p643 (2015-02-25 revision 49749) [x86_64-darwin14.1.0]

#19 楼 @58383788 你试试 2.2.1 吧,我用的 rvm。

23 楼 已删除

我把你的代码下载下来,跑了一下,你的报错信息,没给全,问题在这里 app/helpers/users_helper.rb:3:ingravatar_for' `, 你每章的习题没做吧,gravatar_for 这个 helper 后来有了变化。https://github.com/springwq/fork-twitter/blob/develop/app%2Fhelpers%2Fusers_helper.rb

 User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  User Load (0.2ms)  SELECT "users".* FROM "users"
  Rendered users/index.html.erb within layouts/application (5.5ms)
Completed 500 Internal Server Error in 20ms

ArgumentError (wrong number of arguments (2 for 1)):
  app/helpers/users_helper.rb:3:in `gravatar_for'
  app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb___4000188096406228973_70164692136180'
  app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb___4000188096406228973_70164692136180'

错误是这样的,参数个数问题。

#24 楼 @springwq 尴尬了..改了 users_helper 后确实顺利跑起来了. 我开始学习时候是想着基础太薄弱,习题先空着,照着教程先做第一遍,有个印象,利于第二遍再细致的学习通篇教程,顺带做所有习题。问题竟然是出在这里. 按照你所说我报错信息没有给全,比较奇怪的是,为什么我的机器上显示不出来呢? argumenterror 这一段我的机器上完全没有显示呢,好奇怪啊

#26 楼 @58383788 可能你 ruby 版本的问题,我的 ruby 和 rails 都是最新版本的,也可能你改了 log 的默认设置,导致信息显示不全

#27 楼 @springwq 好的我升级一下版本。有点郁闷.版本影响这么大。非常感谢指导

非常感谢楼上所有人的帮助和指导。我会加紧学习的.感谢你们抽出宝贵的时间。谢谢!

绝对不是 Ruby 版本的问题

今天在这章也碰到问题了,多亏上面的前辈提醒才解决。不得不说这书套路好深

需要 登录 后方可回复, 如果你还没有账号请 注册新账号