Can't put email address field on login form (Authlogic)

后端 未结 7 1417
北恋
北恋 2021-01-31 11:47

So I have Authlogic working fine with this user_sessions/new view:

<% form_for @user_session, :url => user_session_path do |f| %>

  <%          


        
相关标签:
7条回答
  • 2021-01-31 12:12

    It is saying that in UserSession there is no email field. It is not looking at the user, since you have :

    form_for @user_session
    
    0 讨论(0)
  • 2021-01-31 12:21

    I had the same problem and discovered that you have to make sure login is not in your schema and database (you won't need it anyway as you've decided to employ email as I have)

    0 讨论(0)
  • 2021-01-31 12:28

    You are going about this the wrong way:

    Try:

    class UserSession < Authlogic::Session::Base 
      find_by_login_method :find_by_login_or_email
    end 
    

    and in user.rb

    def self.find_by_login_or_email(login)
       find_by_login(login) || find_by_email(login)
    end
    

    Your UserSession has no concept of email (it just knows about login).

    It runs through a process of finding a User given a login, which you can intercept and override (with the find_by_login_method). For an added bonus you can also override, login_field and password_field or even verify_password_method

    0 讨论(0)
  • 2021-01-31 12:28

    I don't know exactly how Authlogic works, but my guess is kind of what you ended with

    But of course my users table has an email field, etc.

    From the sound of it, that doesn't necessarily mean that your UserSession has it, or does it?

    0 讨论(0)
  • 2021-01-31 12:34

    Please check that your user_session inherits UserSession < Authlogic::Session::Base but not < ActiveRecord::Base

    0 讨论(0)
  • 2021-01-31 12:34

    I could be entirely wrong about this but I believe that if you create a user model with an email field and no login field then Authlogic will use this for the UserSession. However, if your user model has a login field but you're not using it (i.e. you switched the view to :email rather than :login) then UserSession will still be looking for login and not email so you'll get the error message.

    If your user model doesn't have a login field then this problem should go away as Authlogic will default to using :email instead.

    0 讨论(0)
提交回复
热议问题