How to access rails association attributes through Handlebar template
-
06-12-2019 - |
سؤال
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?
المحلول
The associated model and attributes-optional, need to be passed to the json in the controller:
post.to_json(:include => :user => {:only => :username })
لا تنتمي إلى StackOverflow