سؤال

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 })

See to_json (apidock)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top