Created
July 26, 2012 19:25
-
-
Save rjfranco/3183995 to your computer and use it in GitHub Desktop.
MealPlan Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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