Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Last active December 14, 2015 13:18
Show Gist options
  • Save romulostorel/5091991 to your computer and use it in GitHub Desktop.
Save romulostorel/5091991 to your computer and use it in GitHub Desktop.
class DemandsController < CrudUpdatedController
def new
object = build_resource
object.academic_year = current_academic_year
super
end
private
def create_resource(object)
object.transaction do
if super
SchoolStatusManager.set_status!(object.school)
end
end
end
end
class AddStatusToSchools < ActiveRecord::Migration
def change
add_column :educacao_schools, :status, :string
School.all.each do |school|
school.update_attribute :status, school.school_status
end
end
end
class SchoolStatusManager
def self.set_status!(school)
school.update_attribute :status, school.school_status
end
end
def school_status
if enrollment_begins_state?
SchoolState::ENROLLMENT_BEGINS
elsif pre_enrollment_state?
SchoolState::PRE_ENROLLMENT
elsif authorized_course_state?
SchoolState::AUTHORIZED_COURSE
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment