开发者

An AuthLogic form is giving me incorrect validation errors -- why?

I set up AuthLogic for Rails according to the AuthLogic example: http://github.com/binarylogic/authlogic_example.

I can log on successfully to the system, but when accessing users/new.html.erb to register a new user, the form returns the following validation errors:

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)

None of these errors exist in the data I am entering.

# 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

I think the problem is that the data isn't being transferred somehow and therefore AuthLogic doesn't think the inputs are sufficient. Do you have any idea why AuthLogic is telling me the data doesn't satisfy its validation?

------MORE INFO------

# User model
class User < ActiveRecord::Base
  acts_as_authentic
  bel开发者_如何学Pythonongs_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


Check params[:user] and see if it's sending the correct values

You can also remove the validation in the model that acts_as_authentic adding the following fields:

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


Just a thought, do you have mass assignment disabled somewhere higher up than your model class?

I have had this happen before where I disabled mass assignment of attributes in my initializers, then forgot to set my model's attributes as accessible using attr_accessible for all required attributes inside the model class.


One thing that is not clear in the documentation and in the videos, is that :password is still required in the attr_accessible line even though you may have crypted_password in the model (i.e. attr_accessible :password).

I'm not certain, but i'm assuming that authlogic uses this password variable to hold the clear text version before it encrypts it.

I don't recommend setting c.validate_password_field = false because this turns off encryption as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜