AuthLogic表单给出了错误的validation错误 – 为什么?

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

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

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  "label" %>
"inputBox", :name => "login", :type => "text" %>
"label" %>
"inputBox", :name => "password", :type => "text" %>
"label" %>
"inputBox", :name => "password_confirmation", :type => "text" %>
"label" %>
"inputBox", :name => "email", :type => "text" %>
# Users controller def new @user = User.new render :layout => "forms" end

我认为问题是数据没有以某种方式传输,因此AuthLogic认为输入不够。 您是否知道为什么AuthLogic告诉我数据不满足其validation?

– – – 更多信息 – – –

 # User model class User  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添加以下字段的validation:

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

只是一个想法,你是否在比模型类更高的位置禁用了批量分配?

我已经在我的初始化程序中禁用了属性的质量分配之前发生了这种情况,然后忘记使用attr_accessible将模型的属性设置为可访问模型类中的所有必需属性。

文档和video中不清楚的一点是:即使您在模型中有crypted_pa​​ssword(即attr_accessible:password),attr_accessible行仍然需要密码。

我不确定,但我假设authlogic在加密之前使用此密码变量来保存明文版本。

我不建议设置c.validate_password_field = false,因为这也会关闭加密。