AuthLogic 表单给出了不正确的验证错误 - 为什么?

2024-01-27

我根据 AuthLogic 示例设置了 AuthLogic for Rails:http://github.com/binarylogic/authlogic_example http://github.com/binarylogic/authlogic_example.

我可以成功登录系统,但是当访问 users/new.html.erb 注册新用户时,表单返回以下验证错误:

Email is too short (minimum is 6 characters)
Email should look like an email address.
Login is too short (minimum is 3 characters)
Login should use only letters, numbers, spaces, and .-_@ please.
Password is too short (minimum is 4 characters)
Password confirmation is too short (minimum is 4 characters)

我输入的数据中不存在这些错误。

# new.html.erb
<%= form.label :login, nil, :class => "label" %><br />
<%= form.text_field :login, :class => "inputBox",
    :name => "login", :type => "text" %><br />

<%= form.label :password, form.object.new_record? ? nil : "Change password", :class => "label"  %><br />
<%= form.password_field :password, :class => "inputBox", 
    :name => "password", :type => "text" %><br />

<%= form.label "Confirm password", nil, :class => "label" %><br />
<%= form.password_field :password_confirmation, :class => "inputBox",
    :name => "password_confirmation", :type => "text" %><br />

<%= form.label :email, nil, :class => "label" %><br />
<%= form.text_field :email, :class => "inputBox",
    :name => "email", :type => "text" %><br />

# Users controller
def new
  @user = User.new
  render :layout => "forms"
end

我认为问题在于数据没有以某种方式传输,因此 AuthLogic 认为输入不够。您知道为什么 AuthLogic 告诉我数据不满足其验证要求吗?

- - - 更多信息 - - -

# User model
class User < ActiveRecord::Base
  acts_as_authentic
  belongs_to :authenticable, :polymorphic => true
end

# Users controller, def create:
def create
    @user = User.new(params[:user])
  if @user.save
    flash[:notice] = "Account registered!"
    redirect_back_or_default account_url
  else
    render :action => :new
  end
end

检查 params[:user] 并查看它是否发送了正确的值

您还可以删除模型中的 actions_as_authentic 验证,添加以下字段:

acts_as_authentic do |c|
 c.validate_login_field = false
 c.validate_email_field = false
 c.validate_password_field = false
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AuthLogic 表单给出了不正确的验证错误 - 为什么? 的相关文章

随机推荐