2010-05-23 2 views
2

AuthLogic 예제에 따라 AuthLogic for Rails를 설정합니다 : http://github.com/binarylogic/authlogic_example.AuthLogic 양식에서 잘못된 유효성 검사 오류가 발생합니다 - 이유는 무엇입니까?

내가 시스템에 성공적으로 로그온 할 수 있지만, 새로운 사용자를 등록/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 [email protected] 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 
+0

생성 작업 및 사용자 모델 코드에 대한 코드를 추가 할 수 있습니까? 루비 콘솔을 통해 사용자를 생성하고 오류가 있는지 확인하십시오. 그리고 하나 – Vamsi

답변

5

확인 PARAMS [: 사용자]를 선택하고 당신은 또한 다음과 같은 필드를 추가 acts_as_authentic 모델의 검증을 제거 할 수 있습니다

올바른 값 전송 않다면 참조 :

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

그냥 생각, 당신은 대량 할당 어딘가 높은 모델 클래스보다 최대 사용할 수 있습니까?

내 이니셜 라이저에서 속성의 대량 할당을 사용하지 않도록 설정 한 다음 모델 클래스의 모든 필수 속성에 대해 attr_accessible을 사용하여 내 모델의 속성을 액세스 가능하도록 설정하는 것을 잊어 버렸습니다.

1

한 일이 아니다 설명서 및 비디오에 명확한 내용은 다음과 같습니다. 모델에 crypted_password (예 : attr_accessible : password)가 있어도 attr_accessible 줄에 암호가 필요합니다.

확실치 않지만 authlogic이이 암호 변수를 사용하여 암호화하기 전에 일반 텍스트 버전을 보유하고 있다고 가정합니다.

암호화를 끄기 때문에 c.validate_password_field = false를 설정하지 않는 것이 좋습니다.