How to access rails association attributes through Handlebar template
-
06-12-2019 - |
Domanda
When a request returns the json that is placed in the handlebar template how/can I access attributes of a rails association like the 'user' of a 'post' as the only attribute in the json is the user_id?
Soluzione
The associated model and attributes-optional, need to be passed to the json in the controller:
post.to_json(:include => :user => {:only => :username })
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow