Question

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?

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top