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

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

  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???

Regards,
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
  end
end

# script/console
>> SomeModel::constant_status
loaded
=> 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.