Created
January 31, 2012 01:59
-
-
Save tdouce/1708223 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 IndividualsController < ApplicationController | |
def update | |
@individual = Individual.find(params[:id]) | |
# When I tried to implement this as a callback I kept getting 'SystemStackError (stack level too deep)' | |
#@individual.untrain | |
if @individual.update_attributes(params[:individual]) | |
flash[:success] = "Individual was updated" | |
redirect_to individuals_url | |
else | |
flash[:failure] = "Individual was NOT updated" | |
render 'edit' | |
end | |
end | |
end | |
class Individual < ActiveRecord::Base | |
#after_update :untrain | |
validates :height, :presence => true, :numericality => true | |
validates :weight, :presence => true, :numericality => true | |
validates :gender, :presence => true | |
MALE = 'Male' | |
FEMALE = 'Female' | |
MALEPROB = 0.5 | |
FEMALEPROB = 0.5 | |
GENDERS = [ MALE, FEMALE ] | |
scope :untrained, Individual.where( :trained => false ) | |
scope :gender, lambda { |gender| where("gender = ?", gender ) } | |
#private | |
def untrain | |
self.update_attributes( :trained => false ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment