【发布时间】:2014-03-04 23:29:52
【问题描述】:
我看过其他关于 Mongoid 和 has_secure_password 的问题,但我的情况不同,在创建“ActiveModel::SecurePassword”时做得很好,password_digest 的创建没有问题。但是,当我尝试进行身份验证时,我收到错误:“undefined method `authenticate' for Mongoid::Criteria:0x007fe2b0d99488”指向行“@room.authenticate(params[:password] )" 我的 checkpoints_controller.rb:
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
在我的样板间.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。
【问题讨论】:
标签: authentication ruby-on-rails-4 mongoid