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

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -