star voting system for proposals

This commit is contained in:
differentreality 2013-08-16 12:46:49 +03:00
parent 2314d943e1
commit 834362491e
17 changed files with 157 additions and 3 deletions

View file

@ -9,8 +9,10 @@ class Event < ActiveRecord::Base
has_many :event_attachments, :dependent => :destroy
has_many :people, :through => :event_people
has_many :speakers, :through => :event_people, :source => :person, :conditions => {"event_people.event_role" => "speaker"}
has_many :votes
has_many :voters, :through => :votes, :source => :person
belongs_to :event_type
has_and_belongs_to_many :registrations
belongs_to :track
@ -62,6 +64,19 @@ class Event < ActiveRecord::Base
end
end
def voted?(event, person)
event.votes.where("person_id = ?", person).first
end
def average_rating
@total_rating = 0
self.votes.each do |vote|
@total_rating = @total_rating + vote.rating
end
@total = self.votes.size
number_with_precision(@total_rating / @total.to_f, :precision => 2, :strip_insignificant_zeros => true)
end
def submitter
result = self.event_people.where(:event_role => "submitter").first
if !result.nil?

View file

@ -8,6 +8,8 @@ class Person < ActiveRecord::Base
has_many :event_people, :dependent => :destroy
has_many :events, :through => :event_people, :uniq => true
has_many :registrations, :dependent => :destroy
has_many :votes, :dependent => :destroy
has_many :voted_events, :through => :votes, :source => :events
validates :first_name, :presence => true
validates :last_name, :presence => true

10
app/models/vote.rb Normal file
View file

@ -0,0 +1,10 @@
class Vote < ActiveRecord::Base
attr_accessible :rating
belongs_to :person
belongs_to :event
delegate :first_name, :to => :person
delegate :last_name, :to => :person
delegate :public_name, :to => :person
end