1

为什么我会收到此错误?我确实在用户表中有“last_signed_in_at”列。

Mysql2::Error:'order 子句'中的未知列'last_signed_in_at'

我的代码是

控制器

@users = @post.likes

看法

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

<%= 调试(@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">]
4

1 回答 1

1

您限定 ActsAsVotable::Vote,但不知何故等待用户 :)

控制器:

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

看法:

<% @users.each do |user| %>
于 2013-01-06T00:26:07.360 回答