内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/1331705/cant-put-email-address-field-on-login-form-authlogic
所以我有一个这个user_sessions /新视图的Authlogic工作正常:
<% form_for @user_session, :url => user_session_path do |f| %>
<% if @user_session.errors.present? %>
Invalid username or password
<% end %>
<%= f.label :login %><br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<br />
<%= f.check_box :remember_me, :style => 'margin-right: 10px' %>
<%= f.label :remember_me %><br />
<br />
<%= f.submit "Login" %>
<% end %>
但是当我改变的时候
<%= f.label :login %><br /> <%= f.text_field :login %><br />
至
<%= f.label :email %><br /> <%= f.text_field :email %><br />
当我加载视图时,我收到此错误:
undefined method `email' for #<UserSession: no credentials provided>
但是当然,我的用户表有一个电子邮件字段等
你会这样做错了:
尝试:
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
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/1331705/cant-put-email-address-field-on-login-form-authlogic
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 表单 – 避免Symfony强制显示表单字段
- .net – 是否可以修改PDF表单字段名称?
- django – 从表单字段输入中清除额外空格的位置?
- 如何在Symfony的表单中添加一个未绑定字段,否则绑定到一个实体?
- springboot~DTO字符字段与日期字段的转换问题
- Protocol Buffers 学习(2):字段类型和其他语言字段类型之间的映射
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
REST in Practice
Jim Webber、Savas Parastatidis、Ian Robinson / O'Reilly Media / 2010-9-24 / USD 44.99
Why don't typical enterprise projects go as smoothly as projects you develop for the Web? Does the REST architectural style really present a viable alternative for building distributed systems and ent......一起来看看 《REST in Practice》 这本书的介绍吧!