DRing DRing - 8 months ago 34
JSON Question

How to convert part of object (and associations) to json in rails

I have a recipe object with a has_many relation for both ingredients and steps. What Im trying to do is convert the recipe_id and just the ingredients and steps into a json string to pass as an argument. I havent worked much with JSON so not sure how to build my own json string.

render :json => @recipe, :include => {:ingredients => {:only => :your_field}}, :except => [:fields_to_exclue]

If you give me the exact fields I can make it better but I believe this is what you are looking for.