Skip to content
Browse files

event: use household_attendee_count

  • Loading branch information...
1 parent 2e620cd commit 019f4a991497439b0c5afe936dfe758e71ec4b67 @mattscilipoti committed Mar 22, 2012
Showing with 16 additions and 7 deletions.
  1. +5 −1 app/models/event.rb
  2. +5 −2 app/models/household.rb
  3. +6 −4 app/views/events/_event.html.haml
View
6 app/models/event.rb
@@ -1,6 +1,10 @@
class Event < ActiveRecord::Base
belongs_to :parent, :class_name => Event.name
- has_and_belongs_to_many :attendees, :class_name => 'Person'
+ has_and_belongs_to_many :attendees, :class_name => 'Person' do
+ def from_household(household)
+ where(:household_id => household)
+ end
+ end
has_many :sub_events, :class_name => Event.name, :foreign_key => 'parent_id'
scope :upcoming, lambda {|limit|
View
7 app/models/household.rb
@@ -1,7 +1,10 @@
class Household < ActiveRecord::Base
before_save :assign_family_name
- has_many :members, :class_name => Person.name#, :inverse_of => :household
-
+ has_many :members, :class_name => Person.name do #, :inverse_of => :household
+ def attending_event(event)
+ joins(:events).where('events_people.person_id in (?)', proxy_association.owner.member_ids)
+ end
+ end
def family_name
read_attribute(:family_name) || assign_family_name
View
10 app/views/events/_event.html.haml
@@ -1,4 +1,6 @@
- related_events = event.sub_events
+- household_attendees_count = event.attendees.from_household(current_person.household).size
+
.event{:id => dom_id(event)}
%p
Our
@@ -8,14 +10,13 @@
%strong.start_date.inline= event.start_date.stamp(date_stamp(:long, false))
at
%strong.start_time.inline= event.start_date.stamp(date_stamp(:time, true))
- ="."
- if related_events.blank?
%p
Currently,
- %strong #{pluralize event.attendees.size, "people"}
+ %strong= "#{event.attendees.size} people"
are expected to attend, with
- %strong 3
+ %strong= household_attendees_count
from your household.
%hr
.details
@@ -26,7 +27,8 @@
%li.badge.badge-info= event.start_date.stamp(date_stamp(:shortest, related_events.blank?))
- if related_events.blank?
%li.badge.attendees{:id => dom_id(event, :attendee_count)}=pluralize event.attendees.size, "Attendee"
- %li.badge.badge-success.household-attendees{:id => dom_id(event, :household_attendee_count)}= "3 from your home"
+ - if household_attendees_count > 0
+ %li.badge.badge-success.household-attendees{:id => dom_id(event, :household_attendee_count)}= "#{household_attendees_count} from your home"
%td.description= event.description
- unless related_events.blank?

0 comments on commit 019f4a9

Please sign in to comment.
Something went wrong with that request. Please try again.