Forum: Ruby on Rails Importing application constants into models and backgroundrb workers - How To?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
vimal (Guest)
on 2009-03-09 08:03
(Received via mailing list)

  I have an app_constants.rb file for defining my constants.
  I need the same constants for checking conditions with my models and
backgroundrb workers.

  When i tried require "app_constants" in my models files it doesn't
suggest any errors but i was unable to use
  the constants either

  Any suggestions???

Vimal Das
MaD (Guest)
on 2009-03-09 09:37
(Received via mailing list)
requiring your file should make them available for your models. there
is something wrong with your code.

# file.rb
CONSTANT = "loaded"

# some_model.rb
class SomeModel < ActiveRecord::Base
  require File.dirname(__FILE__) + '/some/path/to/your/file'
  def self.constant_status
    puts CONSTANT

# script/console
>> SomeModel::constant_status
=> nil
vimal (Guest)
on 2009-03-09 10:24
(Received via mailing list)
Cool.Thank you.

Vimal Das
This topic is locked and can not be replied to.