I kept below code in my model file, self.include_root_in_json = false
First, I tried to get json with following command, SearchTag.find(1).to_json, and got
SearchTag Load (0.1ms) SELECT `search_tags`.* FROM `search_tags` WHERE `search_tags`.`id` = 1 LIMIT 1
=> "{\"search_tag\":{\"id\":1,\"name\":\"test\",\"created_at\":\"2015-04-01T00:00:00.000Z\",\"updated_at\":\"2015-04-01T00:00:00.000Z\"}}"
Then, I added self.include_root_in_json = false in search_tag.rb file, reloaded the console and ran same command and received,
SearchTag Load (0.2ms) SELECT `search_tags`.* FROM `search_tags` WHERE `search_tags`.`id` = 1 LIMIT 1
=> "{\"id\":1,\"name\":\"test\",\"created_at\":\"2015-04-01T00:00:00.000Z\",\"updated_at\":\"2015-04-01T00:00:00.000Z\"}"
Which is desired result, but, I don't get this result in browser... I always get {"search_tags":["test","test1"]}
Aucun commentaire:
Enregistrer un commentaire