Rails as_json include two association

0
down vote
favorite
I am trying to generate json api using as_json . Here I have a feed and
each feed belongs to user and there is another model called feed_like
whose relation is user has many feed_likes and feed has many feed_likes
.

Here in my json I am getting this value :

“feed”: [
{
“id”: 337,
“content”: “iioiio”,
“user_id”: 1,
“created_at”: “2015-10-18T05:37:16.000Z”,
“updated_at”: “2015-10-18T18:01:00.000Z”,
“like_count”: 0,
“user”: {
“id”: 1,
“name”: “Example User”,
“email”: “[email protected]”,
“avatar_url”:
“/system/users/avatars/000/000/001/thumb/download.jpg?1445017351”
}
},
When I am using this code :

e def index

@feed_items = current_user.feed.paginate(page: params[:page],

:per_page => 4)
@feed1 = current_user.feed
#@s = Relationship.where(‘followed_id = ?’,
current_user.followed_id)

@comment = current_user.comments.new
respond_to do |format|
format.json{
render :json => { :Count => @feed1.count,
:feed => @feed_items.as_json(:include =>[:user => { :only =>
[:id,:name,:email],:methods => [:avatar_url]},:feed_likes=>{}]) }
}

end

end
And I want to get the feed_like value inside this json I want the
request like this query :

@like =FeedLike.where(:user_id => “#{current_user.id}”, :feed_id =>
"#{feed.id}
How can I add this query into json request

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs