Last active
December 14, 2015 13:18
-
-
Save romulostorel/5091991 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 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 |
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 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 |
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 SchoolStatusManager | |
def self.set_status!(school) | |
school.update_attribute :status, school.school_status | |
end | |
end |
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
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