Remove the block you're passing to format.json
. You're causing it to ignore your jbuilder file and instead return the result of json: @books
as a response. If you leave the block out:
respond_to do |format|
format.html # index.html.erb
format.json # no block here
end
Then Rails will fall back to its default handling of the response and look for a template in your view directory, it'll find the jbuilder file and render that as the response.