Using rails_admin with rails_api

╄→гoц情女王★ 提交于 2019-12-03 12:41:10

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.

As of v1.0.0 (released September 2016), Rails Admin now supports Rails 5 API-mode straight out-of-the-box. The gem itself injects the missing middleware to render its views and there is no extra configuration required.

Links:

You should have a json view file in this location bookings/index.json.jbuilder And inside this file something like

bookings/index.json.jbuilder

json.name @bookings.name
json.date @bookings.date

This is another template missing

application/index

but really don't know you app completely. So maybe that's the application layout you implemented using ActionView::Layouts. In that case is asking you to implement a layout page file in the location application/index.

NOTE: Those two file inside the views folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!