Sto tentando di ottenere has_secure_password per giocare bene con mongoid. Sto seguendo Railscasts # 270, ma quando ho a SignIn con un nome utente/password, ottengo l'errore:Rails 3.1 Mongo has_secure_password
undefined method `find_by_email' for User:Class
vedo un post simile (http://stackoverflow.com/questions/6920875/mongoid -e-has-secure-password) tuttavia, avendo fatto come suggerito, ho ancora lo stesso errore.
Ecco il mio modello:
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
Controller:
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
Grazie.
Opzione 2 funzionava. Grazie! – Hinchy