Reputation: 79
My application has the following associations. A :review has_many :comments, each comment has a :user that has a :username. In my angular view the following code is not displaying.
<div ng-repeat="comment in review.comments">
{{comment.user.username}}-{{comment.created_at.strftime('%v')}}
</div>
How do I get both the username and the created_at time to show up in my view? I believe it has to do with the render json in my show method in my reviews controller. I'm just not sure how to structure it.
Let me know if you have questions. Thanks in advance!
Upvotes: 0
Views: 50
Reputation: 140
you probably should have included you controller code from rails, however my best guess would be:
index method:
render json: Review.eager_load(comments: [:user]).all.as_json(include: [comments: {include: [:user]}])
show method:
render json: Review.eager_load(comments: [:user]).find(params[:id]).as_json(include: [comments: {include: [:user]}])
Upvotes: 1