我试图让has_secure_password与mongoid玩得很好.我正在关注Railscasts#270,但是当我用用户名/密码登录时,我收到错误:
undefined method `find_by_email' for User:Class@H_502_3@我看到一个类似的帖子(https://stackoverflow.com/questions/6920875/mongoid-and-has-secure-password)但是,按照它的建议完成我仍然得到相同的错误.
这是我的模型:
class User include Mongoid::Document include ActiveModel::SecurePassword validates_presence_of :password,:on => :create attr_accessible :email,:password,:password_confirmation field :email,:type => String field :password_digest,:type => String has_secure_password end@H_502_3@控制器:
class SessionsController < ApplicationController def new end def create user = User.find_by_email(params[:email]) if user && user.authenticate(params[:password]) session[:user_id] = user.id redirect_to root_url,:notice => "Logged in!" else flash.now.alert = "Invalid email or password" render "new" end end def destroy session[:user_id] = nil redirect_to root_url,:notice => "Logged out!" end end@H_502_3@谢谢.