Skip to content

Instantly share code, notes, and snippets.

@rjfranco
Created July 26, 2012 19:25
Show Gist options
  • Save rjfranco/3183995 to your computer and use it in GitHub Desktop.
Save rjfranco/3183995 to your computer and use it in GitHub Desktop.
MealPlan Class
class MealPlan < ActiveRecord::Base
attr_accessible :active
has_many :meals
before_save :check_for_active_plan
def check_for_active_plan
if MealPlan.active.nil?
if self.active == false
flash[:alert] = 'You must have at least one active Meal Plan'
return false
end
else
if MealPlan.active != self && self.active == true
oldplan = MealPlan.active
oldplan.active = false
oldplan.save
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment