为什么会出现此错误?我确实在用户表中有'last_signed_in_at'列。
Mysql2 ::错误:'order clause'中的未知列'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 %>
&lt;%= debug(@users)%&gt;
[#<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">]
答案 0 :(得分:1)
你的范围是ActsAsVotable :: Vote,但不知何故等待用户:)
控制器:
@users = User.where(:id => @post.likes.map(&:voter_id)).order("last_signed_in_at DESC").limit(3)
查看:
<% @users.each do |user| %>