Я постоянно получаю ошибку ActionView :: MissingTemplate при попытке визуализации JSON в моем Rails 5 Api. Я просто хочу отобразить чистый JSON без jbuilder или другого представления. Кто-нибудь может помочь?
thing_controller.rb:
class Api::ThingController < ApplicationController
def thing
render json: {error: 'This is my error message.'}, status: 422
end
end
thing_controller_test.rb:
require 'test_helper'
class Api::ThingControllerTest < ActionDispatch::IntegrationTest
test "the truth" do
get '/api/thing'
assert_response 422
end
end
полное сообщение об ошибке:
Ошибка: Api :: ThingControllerTest # test_the_truth: ActionView :: MissingTemplate: Отсутствует api / вещь / вещь шаблона, приложение / вещь с {: locale => [: en],: форматы => [: json],: options => [ ],: handlers => [: raw,: erb,: html,: builder,: ruby,: jbuilder]}.
application_controller.rb:
class ApplicationController < ActionController::API
include ActionController::Caching
include ActionController::ImplicitRender # want implicit view rendering for JBuilder
before_action :add_cors_headers
def options
head(:ok) if request.request_method == "OPTIONS"
end
to_json
в хэше, который вы возвращаете как JSON? - person max pleaner   schedule 26.04.2016format.json { render json: ... }
- person Малъ Скрылевъ   schedule 26.04.2016