I am using Jbuilder (and I also tried to use Rabl) to render json. When I try to render the jbuilder template in my application it renders the template within the layouts/application file and returns HTML as JSON (see line 'within layouts/application'):
Rides controller on Github
Started GET "/random_photo.json"
Processing by RidesController#random_photo as JSON
>> Rendered rides/random_photo.json.jbuilder within layouts/application (0.3ms)
Rendered shared/_banners_in_corners.haml (3.0ms)
Rendered shared/_sign_in_and_out.haml (2.0ms)
Rendered layouts/_navigation.haml (7.3ms)
Completed 200 OK in 156ms (Views: 120.7ms | ActiveRecord: 3.1ms)
However, when I render the json without a template, and do a render json: @ride.as_json
call, things work as expected.
When I create a new application and I try to do the same thing, everything works as expected as well:
Started GET "/posts/1.json"
Processing by PostsController#show as JSON
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
Rendered posts/show.json.jbuilder (0.6ms)
Completed 200 OK in 20ms (Views: 19.2ms | ActiveRecord: 0.1ms)
I don't know what I have done with my application that it is not rendering the templates correctly. Any ideas?