# Uninitialized constant

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant/120550>\
**Category:** Rails\
**Created:** [November 18, 2007, 11:11am UTC](https://www.ruby-forum.com/t/uninitialized-constant/120550 "2007-11-18T11:11:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 18, 2007, 11:11am UTC](https://www.ruby-forum.com/t/uninitialized-constant/120550/1 "2007-11-18T11:11:54Z")

</div>

hi i am developing my first app with ror and i have experience and  
problem which i could not solve so far … i need a hand please 😉

following scenario…

- i have a file config/project.rb (my application specifc  
configurations) with a module “Project” which holds a constant  
EMAIL\_PATTERN (with a regex pattern for email validation)
- i load this file in the environment.rb with require\_dependency  
“project”
- i have a user model which includes  
validates\_format\_of :email, :with =\> PROJECT::EMAIL\_PATTERN

the problem now:  
i have a view for the user which is fine on the first load … but when i  
submit the form within the view (postback) then i got the error

uninitialized constant User::Project

i dont understand this because i have several unit test which test the  
functionality of validating and there the pattern is applied fine. it  
has only a problem after postback…  
any ideas?

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 19, 2007, 12:37am UTC](https://www.ruby-forum.com/t/uninitialized-constant/120550/2 "2007-11-19T00:37:40Z")

</div>

I’m not sure why you decided to use require\_dependency you might be  
better off using

require File.join(File.dirname( **FILE** ), ‘project’)

Also:

validates\_format\_of :email, :with =\> PROJECT::EMAIL\_PATTERN

should be:

validates\_format\_of :email, :with =\> Project::EMAIL\_PATTERN to match  
the case of the module name.

HTH,  
Nicholas

On Nov 18, 5:11 am, Michal G. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 19, 2007, 12:18pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/120550/3 "2007-11-19T12:18:20Z")

</div>

thanks nicholas… the problem was the require\_dependency … when i use  
the common require then it works fine … i used require\_dependency  
because i want the files be reloaded everytime i change something … i  
dont understand why it does not work with it.

btw: the upper cased project was a typo her in the post
