2016-06-05 2 views
0

설치 프로그램에서 Devise를 설정합니다. 또한 응용 프로그램 컨트롤러에 devise parameter sanitizer를 설치했습니다. 하지만 사용자 정의 매개 변수를 사용하여 가입하면 레일스 로컬 서버 로그에 '허용되지 않은 매개 변수 오류'가 표시됩니다. 이상한 문제는이 작업이 한 번에 작동했다는 것입니다. 이제는 문제가있는 것 같습니다. 내 Devise 구성 및 설명서를 살펴본 후 Sanitizer를 올바르게 설정했습니다.오류 허용되지 않은 매개 변수 오류가 발생했습니다.

Application_Controller :

class ApplicationController < ActionController::Base 
    # Prevent CSRF attacks by raising an exception. 
    # For APIs, you may want to use :null_session instead. 
    include Pundit 
    include Redcarpet 
    protect_from_forgery with: :exception 
    before_action :authenticate_user! 

    rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, :firstname, :lastname, :username) } 
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :password_confirmation, :current_password, :firstname, :lastname, :username) } 
    end 
end 

레일 서버 로그 :

Started POST "/users" for ::1 at 2016-06-05 16:02:57 -0700 
Processing by Devise::RegistrationsController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"PhMqJOEO7fLyUJiWjHcnu+wyB0EQwDeCV9m6XsT5kZ/IyVZ9ZUpwLc26sNbRZleh6xz7V90bvA+yqUBkDkhMmA==", "user"=>{"firstname"=>"Austin", "lastname"=>"Thesing", "username"=>"austinthesing", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"} 
Unpermitted parameters: firstname, lastname, username 
    (0.1ms) begin transaction 
    User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1 
    SQL (0.4ms) INSERT INTO "users" ("email", "encrypted_password", "role", "created_at", "updated_at", "confirmation_token", "confirmation_sent_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["email", "[email protected]"], ["encrypted_password", "$2a$11$KQLR6rLh0qrMfzX90FToP.Yo.i0wmfPkvvw7JOKQIn4smtzk9HJkm"], ["role", 0], ["created_at", "2016-06-05 23:02:57.825074"], ["updated_at", "2016-06-05 23:02:57.825074"], ["confirmation_token", "HMkLUzBwoXB7NZxvYJCA"], ["confirmation_sent_at", "2016-06-05 23:02:57.825333"]] 
    (0.6ms) commit transaction 
    Rendered devise/mailer/confirmation_instructions.html.erb (4.9ms) 
당신은 컨트롤러가 고안 경우 응용 프로그램 컨트롤러에 configure_permitted_parameters 메소드를 호출하는 before_action 콜백을 지정해야

답변

1

제어기

,

또한, 방법은

고안 대해 자세히 알아 강력한 매개 변수 here 주셔서 감사합니다 @elmagnifico

+0

를 보호 것을 볼! 그 before_action 콜백은 기본적으로 다음과 같이 말하고 있습니다 : devise_controller가이 메소드를 먼저 실행하면 .. 그렇습니까? 다시 한번 감사드립니다. – austinthesing

+1

바로! 이 메소드는 실행중인 컨트롤러가 devise 컨트롤러 인 경우에만 호출됩니다. 천만에요 :) –

관련 문제