2016-10-11 3 views
5

rails_admin v0.7.0을 사용하여이 시점에서 클리어런스 젬을 성공적으로 사용했습니다. 오늘 rails_admin을 v1.0으로 업데이트하려고 시도했지만 정의되지 않은 변수 또는 메소드 오류가 발생했습니다 (current_user). v0.7.0에서는 RailsAdmin::MainControllerApplicationController에서 상속 받았지만 v1.0에서는 ActionController::Base에서 직접 상속 받음을 알 수 있습니다. 이는 current_user이 정의되지 않았 음을 의미합니다 (나는 current_user이 클리어런스 젬을 가지고 ApplicationController에 정의되어 있다고 생각합니다). 그러나이 문제를 가진 다른 사람을 찾지 못했기 때문에 나는 뭔가를 놓치고 있다고 생각합니다.rails_admin에서 'current_user'가 정의되지 않았습니다.

나는이 응용 프로그램에 허가를 설정 한 사람이 아니었지만, 우리는이 응용 프로그램에 영향을 줄 수있는 비표준 작업을 수행하고 있다고 생각하지 않습니다. Clearance::ControllerApplicationController에 포함됩니다. current_user의 특별한 정의가 없습니다.

설정/초기화/rails_admin.rb

RailsAdmin.config do |config| 

    # Popular gems integration 

    ## Clearance 
    config.authorize_with do |controller| 
    unless current_user.admin? 
     redirect_to(
     main_app.root_path, 
     alert: "You are not permitted to view this page" 
    ) 
    end 
    end 

    config.current_user_method { current_user } 
end 

답변

8

당신은 레일 관리자는 기본적으로 ::ActionController::Base에서 상속 올바른지, 그리고이 문제를 일으키는 것입니다. 다행히도 수정 사항은 간단합니다. config.parent_controller = "::ApplicationController"config/initializers/rails_admin.rb에 추가 : 당신이 그것을 필요로하는 경우에

RailsAdmin.config do |config| 

    ## == Clearance == 
    config.parent_controller = "::ApplicationController" 

    config.authorize_with do |controller| 
    unless current_user && current_user.admin? 
     redirect_to(
     main_app.root_path, 
     alert: "You are not permitted to view this page" 
    ) 
    end 
    end 

    # You actually don't need this line  
    # config.current_user_method { current_user } 
end 

나는 비교에 대한 reference repo here을 만들었습니다.

+0

'rails_admin'문제에 대한 답변입니다. –

+0

Rails 5 앱에서 Sorcery와 통합 할 때이 기능이 필요했습니다. 감사합니다! –

+0

나는 * 시간 *에 대해이 문제와 씨름하고있었습니다. 감사! – daybreaker

관련 문제