cat
cat

Reputation: 749

Why I cannot fetch all the users who likes post?

Why do I get this error? I do have 'last_signed_in_at' column in users table for sure.

Mysql2::Error: Unknown column 'last_signed_in_at' in 'order clause'

My codes are

controller

@users = @post.likes

view

<% @users.order("last_signed_in_at DESC").limit(3).each do |user| %>
    <li>
        <%= user.profile.nickname %>
        <%= user.last_active_at %>    
    </li>
<% end %>

<%= debug(@users) %>

[#<ActsAsVotable::Vote id: 2, votable_id: 4, votable_type: "Post", voter_id: 1, voter_type: "User", vote_flag: true, created_at: "2012-12-22 13:30:37", updated_at: "2013-01-01 18:55:51">, 
 #<ActsAsVotable::Vote id: 7, votable_id: 4, votable_type: "Post", voter_id: 2, voter_type: "User", vote_flag: true, created_at: "2012-12-23 14:47:04", updated_at: "2013-01-02 00:36:48">]

Upvotes: 1

Views: 87

Answers (1)

Valery Kvon
Valery Kvon

Reputation: 4496

You scope ActsAsVotable::Vote, but somehow waiting for User :)

Controller:

@users = User.where(:id => @post.likes.map(&:voter_id)).order("last_signed_in_at DESC").limit(3)

View:

<% @users.each do |user| %>

Upvotes: 1

Related Questions