# Importing application constants into models and backgroundrb workers - How To?

**URL:** <https://www.ruby-forum.com/t/importing-application-constants-into-models-and-backgroundrb-workers-how-to/162354>\
**Category:** Rails\
**Created:** [March 9, 2009, 7:03am UTC](https://www.ruby-forum.com/t/importing-application-constants-into-models-and-backgroundrb-workers-how-to/162354 "2009-03-09T07:03:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 9, 2009, 7:03am UTC](https://www.ruby-forum.com/t/importing-application-constants-into-models-and-backgroundrb-workers-how-to/162354/1 "2009-03-09T07:03:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 9, 2009, 8:37am UTC](https://www.ruby-forum.com/t/importing-application-constants-into-models-and-backgroundrb-workers-how-to/162354/2 "2009-03-09T08:37:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 9, 2009, 9:24am UTC](https://www.ruby-forum.com/t/importing-application-constants-into-models-and-backgroundrb-workers-how-to/162354/3 "2009-03-09T09:24:07Z")

</div>

Cool.Thank you.

🙂  
Vimal Das
