Skip to content

Instantly share code, notes, and snippets.

@tdouce
Created January 31, 2012 01:59
Show Gist options
  • Save tdouce/1708223 to your computer and use it in GitHub Desktop.
Save tdouce/1708223 to your computer and use it in GitHub Desktop.
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