RailsTutorial 第 9 章:signin_path 是未定义的局部变量吗?电子邮件已经被占用? [英] RailsTutorial Ch 9: signin_path is undefined local variable? Email already taken?

查看:26
本文介绍了RailsTutorial 第 9 章:signin_path 是未定义的局部变量吗?电子邮件已经被占用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 RailsTutorial,但卡在第 9.3 章.当我尝试在 9.3 结束时运行套件测试时,Rspec 不断给我这些错误:

I'm going through RailsTutorial and I'm stuck at chapter 9.3. Rspec keeps giving me these errors when I try to run a suite test at the end of 9.3:

/Users/shaan/Sites/sample_app/spec/support/utilities.rb:15:in `sign_in': undefined local variable or method `signin_path' for #<Class:0x107759358> (NameError)

/Library/Ruby/Gems/1.8/gems/activerecord-3.2.3/lib/active_record/validations.rb:56:in `save!': Validation failed: Email has already been taken (ActiveRecord::RecordInvalid)

首先我得到了最大的错误,然后再次运行测试多次,我一直得到第二个错误.

First I got the top error, then ran the test again many times and I keep getting the second error.

以下是我的控制器路由和测试文件:

Below are my controller routes and test files:

Utilities.rb:

Utilities.rb:

include ApplicationHelper

def full_title(page_title)
  base_title = "Ruby on Rails Tutorial Sample App"
  if page_title.empty?
    base_title
  else
    "#{base_title} | #{page_title}"
  end
end


def sign_in(user)
  visit signin_path
  fill_in "Email",    :with => user.email
  fill_in "Password", :with => user.password
  click_button "Sign in"
  # Sign in when not using Capybara as well.
  cookies[:remember_token] = user.remember_token
end

知道我做错了什么吗?

推荐答案

检查这一行

def sign_in(user)
visit signin_path
...
end

signin_path 似乎不正确.运行 rake routes 以获得正确的路径 &将其替换为 signin_path

signin_path seems to be incorrect. run rake routes to get the correct path & replace that with signin_path

这篇关于RailsTutorial 第 9 章:signin_path 是未定义的局部变量吗?电子邮件已经被占用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆