Using rails_admin with rails_api

后端 未结 3 2108
鱼传尺愫
鱼传尺愫 2021-02-14 16:54

I originally posted this as an issue on rails_api GitHub, but am now posting it here due to inactivity.

I\'m trying to use rails_admin with a Rails 5 API ap

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 17:21

    If I were you, I try isolate API and RailsAdmin controllers. I think this must work:

    class ApplicationController < ActionController::API
      include Knock::Authenticatable
      include Pundit
    end
    
    class RailsAdminCustomController < ApplicationController
      # RailsAdmin support
      include AbstractController::Helpers
      include ActionController::Flash
      include ActionController::RequestForgeryProtection
      include ActionController::MimeResponds
      include ActionController::HttpAuthentication::Basic::ControllerMethods
      include ActionView::Layouts
    end
    

    In config/initializers/rails_admin.rb

    RailsAdmin.config do |config|
      # other config stuff ...
      config.parent_controller = '::RailsAdminCustomController'
    end
    

    Just check the RailsAdmin::ApplicationController here, and the config settings here.

提交回复
热议问题