Does jbuilder do nothing?

I launched a new rails 4 application and want to use it as an API. So this is what I got:

app/controllers/api/v1/teams_controller.rb:

module Api
  module V1
    class TeamsController < ApplicationController
      ...

      def show
        @team = Team.find(params[:id])
      end

      ...
    end
  end
end

app/views/api/v1/teams/show.json.jbuilder:

team ||= @team

json.id team['id']
json.name team['name']

and I get a blank page.

However, when I add render json: @teamto the method show, it gets rendered normally.

Does anyone have an idea what happened to JBuilder?

+4
source share
1 answer

I had the same problem until I added format: 'json'to my route:

get '/api/stuff', to: 'stuff#show', format: 'json'

Hope this helps.

0
source

Source: https://habr.com/ru/post/1536952/


All Articles