Skip to content

Instantly share code, notes, and snippets.

@hamannp
hamannp / team.rb
Created August 19, 2011 19:04
user.rb
class Team
include Mongoid::Document
has_and_belongs_to_many :captains, class_name: 'User', inverse_of: :team_captained, autosave: true
has_and_belongs_to_many :members, class_name: 'User', inverse_of: :team_joined, autosave: true
references_one :owner, class_name: "User", autosave: true
if @messages = Message.all ## need to test for nil
@messages_in_last_week = messages_last_week ## move this out to a method
else
@messages_in_last_week = false
end
def messages_last_week
@messages_in_last_week = @messages.select { |m| m.created_at <= 7.days.ago }
@messages_in_last_week = false if @messages_in_last_week.empty?
## bugs happen if the variable gets assigned [] in one place and false in another