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
24 25 26 27 28 29 30 31 |
# File 'app/models/poll.rb', line 24 def self.find_popular( = {}) .reverse_merge! :limit => 5, :since => 10.days.ago self.includes(:post => :user) .where("polls.created_at > ?", [:since]) .order("polls.votes_count desc") .limit([:limit]) end |
.find_popular_in_category(category, options = {}) ⇒ Object
33 34 35 36 |
# File 'app/models/poll.rb', line 33 def self.find_popular_in_category(category, = {}) .reverse_merge! :limit => 5 self.includes(:post).order('polls.votes_count desc').where('posts.category_id = ?', category.id).references(:posts).limit([:limit]) end |
.find_recent(options = {}) ⇒ Object
19 20 21 22 |
# File 'app/models/poll.rb', line 19 def self.find_recent( = {}) .reverse_merge! :limit => 5 self.includes(:post => :user).order("polls.created_at desc").limit([:limit]) end |
Instance Method Details
#add_choices(choices) ⇒ Object
12 13 14 15 16 17 |
# File 'app/models/poll.rb', line 12 def add_choices(choices) choices.each do |description| choice = self.choices.new(:description => description) choice.save end end |
#voted?(user) ⇒ Boolean
8 9 10 |
# File 'app/models/poll.rb', line 8 def voted?(user) !self.votes.find_by_user_id(user.id).nil? end |