私はもともとan issue on rails_api GitHubとして掲示しましたが、現在は非アクティブのために投稿しています。rails_adminをrails_apiで使用する
rails_admin
をRails 5 APIアプリケーションで使用しようとしています。私は、機能するrails_adminパネルまたは動作中のAPIリクエストを持つことができるまで、余分なActionControllerモジュールを追加しました。問題は、rails_adminがActionView::Layouts
に依存していることが原因であると見なされます。これが含まれると、APIリクエストの問題が発生します。
Gemfile:Railsの管理ダッシュボードが正常に動作すると思われるこれらの変更により
class ApplicationController < ActionController::API
include Knock::Authenticatable
include Pundit
# RailsAdmin support
include AbstractController::Helpers
include ActionController::Flash
include ActionController::RequestForgeryProtection
include ActionController::MimeResponds
include ActionController::HttpAuthentication::Basic::ControllerMethods
include ActionView::Layouts
end
:
module MyApp
class Application < Rails::Application
...
config.middleware.use ActionDispatch::Flash
end
end
I configured extra modules for Rails API、ApplicationControllerに:
gem 'rails', '>= 5.0.0.beta3', '< 5.1'
...
gem 'rack-pjax', github: 'afcapel/rack-pjax'
gem 'remotipart', github: 'mshibuya/remotipart'
gem 'kaminari', github: 'amatsuda/kaminari', branch: '0-17-stable'
gem 'rails_admin', github: 'sferik/rails_admin'
は私がActionDispatch::Flash
を使用するために自分のアプリケーションを構成し。しかし、私は自分のアプリケーションでJSONリソースにアクセスしようとしているとき、次のエラーがスローされます。
Error:
BookingsControllerTest#test_should_get_index:
ActionView::MissingTemplate: Missing template bookings/index, application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :haml]}. Searched in:
* "/Users/richard/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rails_admin-355dc80f8a20/app/views"
テストコード(もformat: :json
を追加してみました):
class BookingsControllerTest < ActionController::TestCase
test 'should get index' do
get :index
assert_response :success
end
end
これはコントローラであり、コード:私はRailsの管理をサポートするために、トップレベルActionController::API
クラスでActionView::Layouts
モジュールが含まれた後
class BookingsController < ApplicationController
def index
@bookings = find_bookings
render json: @bookings, include: ['customer', 'client'], meta: meta
end
end
にのみ起こります。
あなた 'BookingsControllerTest'には?私は、問題がどこにあるのか知っておくと助けになると思います... – Uzbekjon
@Uzbekjonが追加されました。 – richard
rails-apiが推奨する[ActiveModel :: Serializers](https://github.com/rails-api/active_model_serializers)を試したことがありますか? – trueinViso