How to return id in JSON (Rails) -
i'm learning ruby on rails.
my http://localhost:3000/locations.json
returns following:
[{ "name":"abc", "address":"xyz", "latitude":12.3, "longitude":14.5, "url":"http://localhost:3000/locations/1.json" }]
how modify locations_controller.rb
in order json return id
, without parsing url?
[{ "id":1, "name":"abc", "address":"xyz", "latitude":12.3, "longitude":14.5, "url":"http://localhost:3000/locations/1.json" }]
my current locations_controller.rb
contains this:
def index puts "index" @locations = location.all end
thank you.
you try framework rabl gives greater control on output of json. allow specify included in json response.
Comments
Post a Comment