Authlogic不起作用

时间:2013-11-26 05:12:03

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1

我的表单中包含以下3个(用户名,密码,电子邮件)字段。我想根据authlogic验证密码和电子邮件。但我会根据自己的意愿验证用户名。

html.erb

<%= form_for @author do |f| %>
  <%= f.label :username %>
  <%= f.text_field :username %>
  <%= f.label :password %>
  <%= f.text_field :password %>
  <%= f.label :email %>
  <%= f.text_field :email %>
<% end %>

model.rb

 acts_as_authentic                    //to validate (password and email fields)
 acts_as_authentic do |u|
   u.validate_username_field = false //avoid validating username field 
 end

这会引发以下错误。

undefined method `validate_username_field=' for #<Class:0x0000000443cc78>

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

<%= form_for @author do |f| %>
  <%= f.label :username%>
  <%= f.text_field :username%>
  <%= f.label :password%>
  <%= f.text_field :password%>
  <%= f.label :email%>
  <%= f.text_field :email%>

&lt;%end%&gt; acts_as_authentication //验证(密码和电子邮件字段)

acts_as_authentic do |u|;

u.validate_username_field = false //避免验证用户名字段  端