I have a note and it has a certain number of attributes. It also has associated tags. I have been using gon to make this variable available to the javascript files of a page (making @note.attributes available to this page).
I can output the note attributes easily ie if I instantiate:
gon.note = @note.attributes
I can output its content:
alert(gon.note.content)
But, this doesn’t put the notes’ tags through.. I can’t, for example, do :
alert(gon.note.tags)
What if I want to display a note’s tags, but I want to bring them through with gon.note rather than make a whole other variable gon.tags. How might I do this (maybe some sort of joins or include)? I want to do this because it’s better for, say, if you have multiple notes displaying.
If your
@note.tagsis ahas_manyassociation (not a simple array), gon doesn’t know how to serialize an array ofTaginstances.You can do nothing but introduce another variable:
You may want to use Rabl if you need to serialize too many AR objects, since gon supports Rabl.