2013-08-11 2 views
0

내 사용자 이름 필드를 User 모델에 추가했지만 새 사용자 레코드를 만들 때 devise가 인식하지 못하는 것으로 보입니다. 전자 메일, 사용자 이름 및 암호를 채우지 만, 내 params 해시에 분명히 있지만 "사용자 이름을 공백으로 둘 수 없음"이라는 유효성 검사 오류가 발생합니다. 사람들에게 사용자 이름으로 로그인 할 필요는 없지만 새 계정을 등록 할 때 사용자 이름을 설정하기 만하면됩니다.Devise : 사용자 이름 필드를 추가했지만 작동하지 않습니다.

저는 레일 4를 사용하고 있으며, devise의 github README에 언급 된 강력한 매개 변수를 구현했습니다.

다음
<div><%= f.label :username %> 
<%= f.text_field :username %></div> 

내 PARAMS 해시 때이 작업은 다음과 같습니다 여기

application_controller.rb 파일 나는 또한 내 registrations/new.html.erb 파일을 추가 한

class ApplicationController < ActionController::Base 
    protect_from_forgery with: :exception 

    before_filter :configure_permitted_parameters, if: :devise_controller? 

protected 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :username, :password, :password) } 
    end 
end 

여기 내 user.rb 파일

devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable 

before_save { |user| user.username = user.username.downcase } 

validates_presence_of :username 
validates_uniqueness_of :username, case_sensitive: false 

입니다입니다 새로운 사용자 기록을 제출합니다 :

user: !ruby/hash:ActionController::Parameters 
    username: David 
    email: [email protected] 
    password: foobar12 
    password_confirmation: foobar12 

아이디어가 있으십니까?

+2

리틀 발언'user.username이 = user.username.downcase'이 user.username.downcase'로 다시 작성할 수' – hawk

+0

니스! 팁 고마워. – DavidVII

답변

2

밝혀 졌 듯이 위의 강력한 매개 변수는 올바르지 않습니다.

나는이로 변경하여 고정 :

devise_parameter_sanitizer.for(:sign_up) do |u| 
    u.permit(:email, :username, :password, :password_confirmation) 
end 
관련 문제