I’ve been following one of the recipes in the Advanced Rails Recipes
books, and have arrived for my own particular needs at this scenario:
I want to cache some options data in constants at loadtime (as per the
recipe) for dropdown menus in a form
All of the different options are in a single table and use STI.
I have the following module in my initializer folder, with
caches_constant called on the main activerecord data class (RnData):
const_set(self.name.to_s.underscore.upcase, [‘my’, ‘array’,
What happens thus far is that all of the subclasses have a constant
defined with the name of the parent class.
LoadError: Expected /Users/dorian/Sites/mysite/app/models/rn/
rn_auto.rb to define RN_AUTO
load_missing_constant' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:77:inconst_missing_not_from_s3_library’
const_missing' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:89:inconst_missing’
load_missing_constant' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:93:inconst_missing’
Ideally I would like something along the lines of:
as long as it has the right info for the subclass in it, and not just
the parent inherited across all subclass.
So, I’m wondering if there’s a way to write this so that it will run
caches_constant for subclass, or do I have to include the
caches_constants line in all my subclasses?
I’ve replacing caches_constants with this which seems to work, but I’m
worried I may be overwriting something critical in activerecord:
class RnData < ActiveRecord::Base
any help much appreciated!