Skip to content

Instantly share code, notes, and snippets.

@hamannp
Created February 9, 2011 04:13
Show Gist options
  • Save hamannp/817865 to your computer and use it in GitHub Desktop.
Save hamannp/817865 to your computer and use it in GitHub Desktop.
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment