I have a Rails application which displays nested form in json format.
In the JSON Response i am also displaying an id field which represent another table.
How to display name corresponding to that id what i am getting so that i can display both name and id in my json format.
My controller show method
def show
@maintemplate = Maintemplate.find(params[:id])
respond_with (@maintemplate) do |format|
format.json { render :json => @maintemplate }
end
end
Thanks in advance....
render :json => @maintemplate.to_json?["user"]["name"]is the name of the user withuser_id = 12. That user id will also be in the JSON. I've updated my example below to make this clear (but the code is the same).