2016-11-02 26 views
3

enter image description here 我在軌道5,我試圖與我的rails_admin面板的專家實施授權。所以,我包括權威人士在我的應用程序控制器和安裝the rails_admin_pundit gem,你可以在這個片段我的Gemfile的看到:Rails_admin和pundit:未定義的方法`政策'的#<RailsAdmin :: MainController

gem 'devise' 
gem 'devise-i18n' 
gem 'rails_admin', '~> 1.0' 
gem 'rails_admin-i18n' 
gem 'rails_admin_tag_list', github: 'kryzhovnik/rails_admin_tag_list' 
gem 'pundit' 
gem "rails_admin_pundit", :github => "sudosu/rails_admin_pundit" 

應用策略:

class ApplicationPolicy 
    attr_reader :current_user, :record 

    def initialize(current_user, record) 
    @user = current_user 
    @record = record 
    end 

    def index? 
    false 
    end 

    def show? 
    scope.where(:id => record.id).exists? 
    end 

    def create? 
    false 
    end 

    def new? 
    create? 
    end 

    def update? 
    false 
    end 

    def edit? 
    update? 
    end 

    def destroy? 
    false 
    end 

    def rails_admin?(action) 
     case action 
     when :dashboard 
      @user.admin? 
     when :index 
      @user.admin? 
     when :show 
      @user.admin? 
     when :new 
      @user.admin? 
     when :edit 
      @user.admin? 
     when :destroy 
      @user.admin? 
     when :export 
      @user.admin? 
     when :history 
      @user.admin? 
     when :show_in_app 
      @user.admin? 
     else 
      raise ::Pundit::NotDefinedError, "unable to find policy #{action} for #{record}." 
     end 
    end 

end 

而且我rails_admin初始化的一個片段:

RailsAdmin.config do |config| 
    config.authorize_with :pundit 
    config.current_user_method(&:current_user) 
    ... 
end 

所以,現在當我加載的管理儀表板(URL: 「/ admin」 的),我得到這個錯誤:

undefined method `policy' for #RailsAdmin::MainController:0x0055914e2523a0>

我遵循了所有的指示,但我仍然沒有看到缺少的東西。任何答案/建議將不勝感激。

回答

相關問題