Skip to content

Instantly share code, notes, and snippets.

@felipemesquita
Created June 26, 2012 16:50
Show Gist options
  • Save felipemesquita/2997040 to your computer and use it in GitHub Desktop.
Save felipemesquita/2997040 to your computer and use it in GitHub Desktop.
scope :active, where(:active => true)
before_create :activate!
def activate!
self.organization.surveys.update_all(:active => false)
self.active = true
end
scope :active, where(:active => :true)
before_save :update_active
def update_active
last_active = Survey.active.first
last_active.update_column(:active, false)
self.active = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment