15

I want to use Jbuilder with Rails 5.0.0.beta1.1 in API mode. Out of the box, it doesn't work, even when creating the app/views directory.

For example, I have:

# app/controllers/tests_controller.rb
class TestsController < ApplicationController
  # The requests gets inside the action
  def test
  end
end

# app/views/tests/test.json.jbuilder
json.test "It works!"

The error I'm getting is

No template found for TestsController#test, rendering head :no_content

I guess I have to change some things in the config files. What do I have to do?

2

3 Answers 3

9

Doing an explicit render from the controller like this works:

render 'controller_name/action.json.jbuilder'
4

With API mode.

You need include module like bellow

class ApplicationController < ActionController::API
  include ActionController::ImplicitRender # if you need render .jbuilder
  include ActionView::Layouts # if you need layout for .jbuilder
end
3

I got the same error, but in my case I had simply forgotten to add the jbuilder gem in the Gemfile:

gem 'jbuilder', '~> 2.5'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.