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": "ni...@jumpbook.in",
    "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

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/26812563cf4bbd71da74caf433bb26cd%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to