Rails教程意外失败/错误:get:show,:id => @用户

时间:2011-06-26 20:51:57

标签: ruby-on-rails rspec

我目前正在阅读令人敬畏的Rails教程,在我执行git重置以返回之前的提交后,有些东西破坏了我的数据库,突然间我在运行rspec时遇到了5次失败。

Failures:

  1) UsersController Get 'show' should be successfull
     Failure/Error: get :show, :id => @user
     ActionView::Template::Error:
       undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xaad9990>
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
     # ./spec/controllers/users_controller_spec.rb:13:in `block (3 levels) in <top (required)>'

  2) UsersController Get 'show' should find the right user
     Failure/Error: get :show, :id => @user
     ActionView::Template::Error:
       undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xa820ca8>
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
     # ./spec/controllers/users_controller_spec.rb:18:in `block (3 levels) in <top (required)>'

  3) UsersController Get 'show' should have the right title
     Failure/Error: get :show, :id => @user
     ActionView::Template::Error:
       undefined method `gravatar_for' for #<#<Class:0xaadc884>:0x9f0e7b4>
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
     # ./spec/controllers/users_controller_spec.rb:23:in `block (3 levels) in <top (required)>'

  4) UsersController Get 'show' should include the user's name
     Failure/Error: get :show, :id => @user
     ActionView::Template::Error:
       undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb930cc8>
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
     # ./spec/controllers/users_controller_spec.rb:28:in `block (3 levels) in <top (required)>'

  5) UsersController Get 'show' should have a profile image
     Failure/Error: get :show, :id => @user
     ActionView::Template::Error:
       undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
     # ./spec/controllers/users_controller_spec.rb:33:in `block (3 levels) in <top (required)>'

我确信这很容易解决,但老实说,我不知道哪里可以看。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

这是你的问题:

 undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>

您需要确保在个人资料模型中指定了重力数字。

答案 1 :(得分:0)

您正在呼叫gravatar_for,这是未知的,第5行:./app/views/users/show.html.erb

即使这已经是答案,请提供详细信息以便我们解决。

我很确定您忘记将该方法添加到User模型中。