2017-12-02 3 views
0

내 앱에 가입하려면 나이가 있어야합니다. 나는 devise gem을 사용하고 있지만, 나이를 확인하기 위해 내 사용자 모델에 메소드를 만들었습니다 .... 내가 원하는 것은 무엇이든 무제한 클래스로 인해 할 수 없다는 오류가 발생합니다. 기본적으로 사용자가 있지만 birth_date 사용자가 저장하지 않습니다.Devise gem 등록 모델 문제

나는이 논리를 어디에두고 있는지가 잘못된 장소에 있음을 알려줍니다. 그러나 나는 어디 있는지 모른다. 등록 컨트롤러와 사용자 컨트롤러가 있습니다. 나는 또한 사용자 모델을 가지고있다. 나는 등록 모델을 가지고 있지 않다. 나는 두 가지 방법 중 하나가 가지고 있지 않은 다른 모델에 있어야하는지 궁금하다. 아니면 내가 잘못 제작하고있다. 내가 devise_parameter_sanitizer에 입력 할 때

내 사용자 모델

class User < ActiveRecord::Base 
    before_create :age_restriction 

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

    def age_restriction 
    if (self.birth_date&.to_date + 18.years) < Date.today # assuming dob format is mm/dd/yy 
     errors.add :birth_date, 'must be older than 18' 
    end 
    end 
end 

내 등록 모델은

Cass RegistrationsController < Devise::RegistrationsController 
    before_action :configure_sign_up_params, only: :create 
    before_action :configure_account_update_params, only: :update 

    protected 

    def configure_sign_up_params 
    devise_parameter_sanitizer.permit(:sign_up, keys: [:bith_date, :first_name, :last_name]) 
    binding.pry 
    end 

    def configure_account_update_params 
    devise_parameter_sanitizer.permit(:account_update, keys: [:birth_date, :first_name, :last_name]) 
    end 
end 

내가 거기에 가지고있는 중단 점, 나는

@permitted= 
    {:sign_in=>[:email, :password, :remember_me], 
    :sign_up=> 
    [:email, :password, :password_confirmation, :bith_date, :first_name, :last_name], 
    :account_update=>[:email, :password, :password_confirmation, :current_password]}, 
@resource_name=:user> 

답변

0

오타를 얻을. 현재, : bith_date입니다. birth_date으로 고쳐서 모델이 적절한 속성을 읽을 수 있어야합니다. 당신이 허용하는 PARAM이 :bith_date

가 sign_up_params에 :birth_date을 허용있는 동안, self.birth_date를 확인하고 이후

그것은, 전무했다.

+0

오 이런 ...... 정말 고마워요! – kdweber89

관련 문제