In my Ruby on rails based project I’d like to handle a couple of fairly complex form (nested models) with json and knockout js.
The idea is to resemble the Rails Model(s) with the knockout js viewModels and once the user has composed/compiled the fields the whole json gets posted the a normal Rails controller and turned into an instance of Rails Model for further manipulation and/or persisting.
Is there any gem/guide/tutorial/article that I can read to do this?
Does rails handle automatically incoming json requests? Even with nested models?
Here is a fairly recent tutorial which demonstrates one way to do what I think you’re asking: http://railscasts.com/episodes/196-nested-model-form-part-1
Follow @Jakob’s link to see how rails decodes json requests. When I write ajaxy code, I find that most often I am better off writing it to submit the proper get/post requests with an expected json return type.
For example: If I’m doing a lookup to populate some search results and I want it to return json data I would probably write a form that submits to this url:
http://application/search.json?query=foo+barThen, in the rails controller I can easily provide a DRY search action with respond_to.