मैं mongoid के साथ अच्छा खेलने के लिए has_secure_password प्राप्त करने का प्रयास कर रहा हूं।रेल 3.1 Mongoid has_secure_password
undefined method `find_by_email' for User:Class
मैं एक ऐसी ही पोस्ट देखें (http://stackoverflow.com/questions/6920875/mongoid: मैं Railscasts अनुसरण कर रहा हूँ # 270 है, लेकिन जब मैं एक उपयोगकर्ता नाम/पासवर्ड के साथ प्रवेश द्वारा के लिए, मैं त्रुटि मिलती है -और-सुरक्षित-पासवर्ड) हालांकि, जैसा कि सुझाव दिया गया है, मैंने अभी भी वही त्रुटि प्राप्त की है।
यहाँ मेरी मॉडल है:
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
नियंत्रक:
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
धन्यवाद।
विकल्प 2 महान काम किया। धन्यवाद! – Hinchy