I defined user configuration options in my rails application (hash APP_CONFIG). OK, now how can I use these variables in my models? By directly calling APP_CONFIG ['variable'] in models, these are not rails! For example, I can use these models without the Rails framework. Then APP_CONFIG will not be defined.
ATM I use a model observer and assign global configuration variables with instance variables, for example:
def after_initialize model
Mongoid.observers.disable :all do
model.user_id = APP_CONFIG['user_id'])
model.variable = User.find(model.user_id).variable
end
end
But this solution looks like a monkey patch. Is there a better way?
Or should I keep it simple and can just define the APP_CONFIG hash in a new application (not a Rails application)?
enRai source
share