It is often useful to make them part of the model, and not make them constants, but class variables. So instead of:
FOO="bar" in enviromoment.rb, you'd have: class Biz < ActiveRecord::Base self.def foo @@foo ||= "bar" end This means you can also make changes if you someday need to have it become dynamic, and you can use a mock to override foo if you need that for testing. Note, if you really need it to be a constant (really, you probably don't, but it could happen ;-) you can still stuff it in the class and call Biz::FOO instead of FOO or Biz.foo Rob On 7/24/07, Matt Aimonetti <[EMAIL PROTECTED]> wrote:
In edge you have a config/initializers folder to avoid putting stuff in your environment.rb file. I don't know if that would solve your problem but that's what you will have to do in 2.0 Regarding the constants, put them where they make sense. If you need to use them often in a model, maybe they should be in your model. Matt On 7/24/07, Glenn Little <[EMAIL PROTECTED]> wrote: > I typically define my global constants in environment.rb at the > bottom. However, I've got a situation where I've got a > > config.active_record.observers > > call earlier on in the Rails::Initializer.run loop (of environment.rb) > > That observer config call pokes one of my models. That model > uses some of my constants in validate_* calls. The problem is, > at the time that model code gets poked, the constants are not > yet defined. > > Is there some other "standard" place to define constants? I have > tried just stuffing the definitions inside the Initializer.run > loop (and before the observer config), and that does avoid the > error. But is there a better place than that? I like sticking > with the conventions and standards when at all possible. > > Maybe I'll just define all my local constants at the top of the file instead > and be done with it. Any reason that I'm missing that makes that > a bad idea? > > Thanks. > > -glenn > _______________________________________________ > Sdruby mailing list > [email protected] > http://lists.sdruby.com/mailman/listinfo/sdruby > -- m|a agile development -------- (760) 536-4425 Skype: mattdesktop GTalk: [EMAIL PROTECTED] blog: http://railsontherun.com _______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
