我有帖子模型
class Post < ActiveRecord::Base
acts_as_voteable
end
和投票模型
class Vote < ActiveRecord::Base
scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.name]) }
scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.name]) }
scope :recent, lambda { |*args| where(["created_at > ?", (args.first || 2.weeks.ago)]) }
scope :descending, order("created_at DESC")
belongs_to :voteable, :counter_cache=>true,:polymorphic => true,:touch=>true
belongs_to :voter, :polymorphic => true
attr_accessible :vote, :voter, :voteable
# Comment out the line below to allow multiple votes per user.
validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
end
当我用这些方法获得帖子选民时
<% @post.voters_who_voted.each do |voter|%>
<%= voter.name %>
<% end %>
我加载我的数据库如何从这些数组中只选择用户名和用户 ID?
更新我更改了我的代码我正在使用 thumbs_up gem 我首先粘贴了更少的代码以简化问题