rails 5 authlogic 隐秘 user_session 错误

rails 5 authlogic cryptic user_session error

我正在尝试使用 Rails 5(因此是 user_session_params.to_h)设置 Authlogic,当我尝试创建新会话时,我收到以下错误消息不知道该怎么办。任何建议将不胜感激。

输入@user_session.errors.inspect

#<Authlogic::Session::Validation::Errors:0x0000000cb9b7a0 @base=#<UserSession: {:email=>"test@test.com", :password=>"<protected>"}>, @messages={:base=>["You did not provide any details for authentication."]}, @details={:base=>[{:error=>"You did not provide any details for authentication."}]}>

代码如下:

UserSessionsController

class UserSessionsController < ApplicationController
  def new
    @user_session = UserSession.new
  end

  def create
    @user_session = UserSession.new(user_session_params.to_h)
    puts @user_session.errors.inspect

    if @user_session.save
      flash[:notice] = "Login successful, thank you!"
      redirect_to users_path
    else
      flash[:notice] = "Something went wrong, sorry."
    end
  end

  def destroy
    current_user_session.destroy
    redirect_to new_user_sessions_path
  end

  private

  def user_session_params
    params.require(:user_session).permit(:email, :password, :remember_me)
  end
end

用户会话

class UserSession < Authlogic::Session::Base
end

查看

<%= form_for @user_session, url: user_sessions_path, method: :post, html: {class: 'form-horizontal', role: 'form'} do |f| %>
    <div class='form-group'>
      <%= f.email_field :email, class: 'form-control', placeholder: 'Login' %>
    </div>
    <div class='form-group'>
      <%= f.password_field :password, class: 'form-control', placeholder: 'Password' %>
    </div>
    <%= f.submit 'Login', class: 'btn btn-primary' %>
<% end %>

用户

class User < ApplicationRecord
    acts_as_authentic do |c|
        c.login_field = 'email'
    end
end

Rails5 下似乎有一个 A​​uthlogic 问题。

您可能已经看到 this comment from github issue 487 but you probably followed only the first step. The step nr. 2 deals with broken Authlogic callbacks under Rails 5 and there is a link to pull request #488 开发修复程序的地方。目前,您唯一的选择似乎如下:

  • 你可以在拉取请求 488 中尝试 this branch of Authlogic that allegedly has the callbacks issue fixed, as commented
  • 您当然可以等到事情稳定下来,Authlogic 获得对 Rails5.
  • 的官方支持

从 Authlogic 版本 3.5.0 开始,这个问题似乎已得到解决。目前 3.5.0 仍未作为稳定版本发布,但在 Gemfile 中指定 3.5 应该可以解决问题(无论如何它对我有用):

gem 'authlogic', '~> 3.5'