ruby-on-rails - AuthLogic 表单给我不正确的验证错误——为什么?

标签 ruby-on-rails validation authlogic

我根据 AuthLogic 示例为 Rails 设置了 AuthLogic: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] 并查看它是否发送了正确的值

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

acts_as_authentic do |c|
 c.validate_login_field = false
 c.validate_email_field = false
 c.validate_password_field = false
end

关于ruby-on-rails - AuthLogic 表单给我不正确的验证错误——为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2890652/

相关文章:

ruby-on-rails - 带有设计的 Turbo-Rails 不会始终如一地重定向 Rails 6.1.3 设计 4.7.3 Turbo Rails 0.5.9

ruby-on-rails - 如何根据规范更改 Rails 应用程序配置?

ruby-on-rails - 如何将数据库结果中的行转换为列

数字输入的 C++ 输入验证

unit-testing - 使用 Authlogic on Rails 3 进行单元测试

ruby-on-rails - 您可以使用 Authlogic 检查以前使用过的密码(密码历史记录)吗?

ruby-on-rails - 之后(:each) vs after(:all) in Rails rspec

java - @Size hibernate注解可以继承吗?

jquery - 使用 Selenium 时验证 DOM 操作