Пишу User-аутентификацию для Rails приложения. Столкнулся с такой ошибкой (указана в заголовке вопроса)
models/user.rb
class User < ActiveRecord::Base
attr_accessor :password, :password_confirmation
before_save :encrypt_password
validates :email, presence: true
validates :password, length: {minimum: 6}, confirmation: true
protected
def encrypt_password
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
def self.authenticate(params)
user = find_by_email(params[:email])
if user && user.password_hash == BCrypt::Engine.hash_secret(params[:password], user.password_salt)
user
else
nil
end
end
end
accounts_controller
class AccountsController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(signup_params)
if @user.save
User.authenticate(params[:email], params[:password])
redirect_to root_path, notice: "Вы успешно зарегистрировались"
else
render 'new'
end
end
def signin
@user = User.new
end
def authenticate
@user = User.authenticate(signin_params)
if @user
redirect_to root_path, notice: "Вы успешно вошли"
else
render 'signin'
end
end
private
def signup_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
def signin_params
params.require(:user).permit(:email, :password)
end
end
Часть роутов, ответственных за все это:
resource :account, as: :users do
collection do
get 'signin', to: 'accounts#signin'
post 'authenticate', to: 'accounts#authenticate'
end
end
форма (haml)
%h1 Вход
= form_for @user, url: authenticate_users_path do |f|
%p
= f.label :email
= f.email_field :email
%p
= f.label :password
= f.password_field :password
%p
= f.submit
Почему при оправке формы siging выдается такая ошибка? Как правильно организовать?