无法在登录表单上放置电子邮件地址字段(Authlogic)
所以我使用这个user_sessions/new
视图使Authlogic正常工作:
user_session_path do |f| %> Invalid username or password
'margin-right: 10px' %>
但是当我改变的时候
至
加载视图时出现此错误:
undefined method `email' for #
但是我的用户表当然有一个email
字段等。
你这是错误的方式:
尝试:
class UserSession < Authlogic::Session::Base find_by_login_method :find_by_login_or_email end
并在user.rb中
def self.find_by_login_or_email(login) find_by_login(login) || find_by_email(login) end
您的UserSession没有电子邮件的概念(它只知道登录)。
它运行一个查找用户登录的过程,您可以拦截和覆盖(使用find_by_login_method
)。 要获得额外奖励,您还可以覆盖, login_field
和password_field
甚至verify_password_method
假设您使用的是用户模型,在Authlogic中使用电子邮件进行身份validation的最简单方法是:
class User < ActiveRecord::Base acts_as_authentic do |c| c.login_field = 'email' end end
请检查您的user_session是否inheritance了UserSession
我遇到了同样的问题,并发现你必须确保登录不在您的架构和数据库中(因为您决定使用我的电子邮件,所以无论如何都不需要它)
我可能完全错了,但我相信如果你创建一个带有电子邮件字段且没有登录字段的用户模型,那么Authlogic将把它用于UserSession。 但是,如果您的用户模型有登录字段但您没有使用它(即您将视图切换为:电子邮件而不是:登录),那么UserSession仍将查找登录而不是电子邮件,因此您将收到错误消息。
如果您的用户模型没有登录字段,则此问题应该消失,因为Authlogic将默认使用:email。
我不确切知道Authlogic是如何工作的,但我的猜测是你最终的结果
但是我的用户表当然有一个电子邮件字段等。
从它的声音来看,这并不一定意味着你的UserSession拥有它,或者它是否具有它?
据说在UserSession中没有电子邮件字段。 它没有关注用户,因为你有:
form_for @user_session
- 使用AuthlogicvalidationAPI
- 如何让authlogic使用Rails会话而不是自己的cookie?
- Rails中的会话,子域和authlogic问题
- Ruby on Rails:添加Facebook登录,Twitter登录,OpenID登录等的最佳方式
- 使用Authlogic进行集成测试?
- Rails + Authlogic @current_user问题 – “显示”方法不再有效
- 使用google配置authlogic-oauth
- AuthLogic UserSessions Controller返回Nil
- Rails,没有密码的Authlogic(注册确定.user_sessionvalidation失败)