Skip to content

Instantly share code, notes, and snippets.

@awoodworth
Created November 20, 2016 02:09
Show Gist options
  • Save awoodworth/bc7d9295848a150f715f291677ad82b8 to your computer and use it in GitHub Desktop.
Save awoodworth/bc7d9295848a150f715f291677ad82b8 to your computer and use it in GitHub Desktop.
Rails - Reload Classes
class Setting < ActiveRecord::Base
validates :name, :value, presence: true
validates :name, uniqueness: true
after_update :reload_classes
#..
private
# reload_classes is a hack way around loading settings into FINALS
def reload_classes
klasses = [:User, :Group]
# unload classes
Object.class_eval do
klasses.each do |klass|
remove_const klass.to_s if const_defined? klass.to_s
end
end
# reload classes
klasses.each do |klass|
load "#{klass.to_s.underscore}.rb"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment