Rails 病马寻良医,SessionHelper 错误 !

sensi · 2014年04月13日 · 最后由 sensi 回复于 2014年04月14日 · 3285 次阅读

报错:


Failures:

  1) AuthenticationPages GET /authentication_pages should hava the title 'sign in'
     Failure/Error: visit signin_path
     ActionController::RoutingError:
       uninitialized constant ApplicationController::SeesionsHelper
     # ./app/controllers/application_controller.rb:6:in `<class:ApplicationController>'
     # ./app/controllers/application_controller.rb:1:in `<top (required)>'
     # ./app/controllers/sessions_controller.rb:1:in `<top (required)>'
     # ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'

  2) AuthenticationPages signin with valid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf089210>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  3) AuthenticationPages signin with valid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf4308f0>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  4) AuthenticationPages signin with valid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf643e58>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  5) AuthenticationPages signin with valid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf791a80>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  6) AuthenticationPages signin with valid information with invalid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf0a8638>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  7) AuthenticationPages signin with valid information with invalid information 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf438ca8>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

  8) AuthenticationPages signin with valid information with invalid information after visiting another page 
     Failure/Error: click_button "Sign in"
     NoMethodError:
       undefined method `sign_in' for #<SessionsController:0x007f9dbf6496a0>
     # ./app/controllers/sessions_controller.rb:9:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'

Finished in 1.05 seconds
42 examples, 8 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:14 # AuthenticationPages GET /authentication_pages should hava the title 'sign in'
rspec ./spec/requests/authentication_pages_spec.rb:44 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:45 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:43 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:46 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:28 # AuthenticationPages signin with valid information with invalid information 
rspec ./spec/requests/authentication_pages_spec.rb:29 # AuthenticationPages signin with valid information with invalid information 
rspec ./spec/requests/authentication_pages_spec.rb:32 # AuthenticationPages signin with valid information with invalid information after visiting another page 


----------------
application_controller.rb文件



```shell
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  # protect_from_forgery with: :exception
  protect_from_forgery 
  include SessionsHelper

end

sessions_helper.rb 文件

module SessionsHelper
    def sign_in(user)
        cookies.permanent[:remember_token] = user.remember_token
        self.current_user = user 
    end

    def signed_in? 
        !current_user.nil?
    end

    def current_user=(user) 
        @current_user = user
    end
    def current_user
        @current_user ||= User.find_by_remember_token(cookies[:remember_token])
    end
end

include SeesionHelper 这里错了

应该是 include SessionHelper

#1 楼 @kai209209 已经修改过了 是 SessionsHelper,但还是错误

文件名 sessions_helper.rb

4 楼 已删除

what's new error messages?

请注意一下是不是单复数问题,因为你的 RoutingError 找不到呀对应 route 呀

哎呀,果然是一大失误!!拼写错误!以后要认认真真的,

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