【发布时间】:2010-05-23 04:11:21
【问题描述】:
我根据 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
【问题讨论】:
-
能否请您添加创建操作的代码以及您的用户模型代码?尝试通过 ruby 控制台创建用户,看看是否有任何错误。还有一个
标签: ruby-on-rails validation authlogic