Authentication 未定义的方法`验证';在Rails 4中,Mongoid具有\u安全\u密码
我看到了其他关于Mongoid的问题,并且有安全的密码,但我的情况不同,在创建“ActiveModel::SecurePassword”时做得很好,密码摘要创建没有问题。但是,当我尝试进行身份验证时,会出现错误:“Mongoid::Criteria:0x007fe2b0d99488的未定义方法“authenticate”“指向我的检查点的行”@room.authenticate(params[:password])”\u controller.rb:Authentication 未定义的方法`验证';在Rails 4中,Mongoid具有\u安全\u密码,authentication,ruby-on-rails-4,mongoid,Authentication,Ruby On Rails 4,Mongoid,我看到了其他关于Mongoid的问题,并且有安全的密码,但我的情况不同,在创建“ActiveModel::SecurePassword”时做得很好,密码摘要创建没有问题。但是,当我尝试进行身份验证时,会出现错误:“Mongoid::Criteria:0x007fe2b0d99488的未定义方法“authenticate”“指向我的检查点的行”@room.authenticate(params[:password])”\u controller.rb: def create @room
def create
@room = Room.where(url: params[:room_url])
if @room && @room.authenticate(params[:password])
session[@room.id.to_s.to_sym] = true
redirect_to "/chat/" + @room.url
else
redirect_to "/checkpoint/" + @room.url, alert: "This room may not exists or your password is incorrect."
end
end
在my model room.rb中,一切似乎都很好:
class Room
include Mongoid::Document
include ActiveModel::SecurePassword
embeds_one :guest
embeds_many :messages
has_secure_password
field :password_digest
field :owner_name
field :url
end
我正在使用:Rails 4.0.0和Mongoid 4.0.0.beta1。替换这一行
@room = Room.where(url: params[:room_url])
@room = Room.where(url: params[:room_url]).first
用这条线
@room = Room.where(url: params[:room_url])
@room = Room.where(url: params[:room_url]).first
我正在处理类似的情况。对我有效的方法是在字段密码摘要之后移动has_secure_密码
教室
include Mongoid::Document
包括ActiveModel::SecurePassword
第一位:客人
嵌入许多:消息
字段:密码\u摘要
有安全的密码吗
字段:所有者名称
字段:url
结束