Class: Poll
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Poll
- Defined in:
- app/models/poll.rb
Class Method Summary collapse
- .find_popular(options = {}) ⇒ Object
- .find_popular_in_category(category, options = {}) ⇒ Object
- .find_recent(options = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_popular(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/models/poll.rb', line 25 def self.find_popular( = {}) .reverse_merge! :limit => 5, :since => 10.days.ago find(:all, :order => "polls.votes_count desc", :limit => [:limit], :include => [:post => :user], :conditions => ["polls.created_at > ?", [:since]] ) end |
.find_popular_in_category(category, options = {}) ⇒ Object
35 36 37 38 |
# File 'app/models/poll.rb', line 35 def self.find_popular_in_category(category, = {}) .reverse_merge! :limit => 5 self.includes(:post).order('polls.votes_count desc').limit([:limit]).where('posts.category_id = ?', category.id) end |
.find_recent(options = {}) ⇒ Object
20 21 22 23 |
# File 'app/models/poll.rb', line 20 def self.find_recent( = {}) .reverse_merge! :limit => 5 find(:all, :order => "polls.created_at desc", :limit => [:limit], :include => [:post => :user]) end |
Instance Method Details
#add_choices(choices) ⇒ Object
13 14 15 16 17 18 |
# File 'app/models/poll.rb', line 13 def add_choices(choices) choices.each do |description| choice = self.choices.new(:description => description) choice.save end end |
#voted?(user) ⇒ Boolean
9 10 11 |
# File 'app/models/poll.rb', line 9 def voted?(user) !self.votes.find_by_user_id(user.id).nil? end |