我正在使用Thumbs_up创建投票功能的gem。我有3个表格 - 发布,用户和投票,邮政是acts_as_voteable和用户是acts_as_voter。如何在Ruby on Rails中获取未投票的帖子数
型号Post.rb
class Post < ActiveRecord::Base
attr_accessible :title, :content, :user_type
acts_as_voteable
validates_presence_of :title,:content
default_scope order: 'posts.created_at DESC'
end
型号Vote.rb
class Vote < ActiveRecord::Base
scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]) }
scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]) }
scope :recent, lambda { |*args| where(["created_at > ?", (args.first || 2.weeks.ago)]) }
scope :descending, order("created_at DESC")
belongs_to :voteable, :polymorphic => true
belongs_to :voter, :polymorphic => true
attr_accessible :vote, :voter, :voteable
end
型号User.rb
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
acts_as_voter
has_many :posts, dependent: :destroy
end
现在我想算的职位数量的,没有投票。我试图这样做..
<%= Post.joins(:votes).where("dont_know_how_to_write_condition").count %>
任何帮助?在此先感谢
这是MySQL或PostgreSQL? – Lucas 2013-05-10 08:29:26
在开发模式我使用的是SQLite和在生产模式下我使用postgresql – SoftwareGeek 2013-05-10 08:33:30