# Method\_missing only in production using custom validation

**URL:** <https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770>\
**Category:** Rails\
**Created:** [January 15, 2009, 5:00am UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770 "2009-01-15T05:00:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [January 15, 2009, 5:00am UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770/1 "2009-01-15T05:00:41Z")

</div>

I’ve written a custom validation ah la advanced rails recipes. When i’m  
in development everything works great. As soon as I “script/server -e  
production”  
then my console gets lit up with errors [http://www.pastie.org/361177](http://www.pastie.org/361177)

I played around with what actions cause this, and apparently putting

validates\_anything\_not\_standard :anything

causes an error.

This includes having the validation in my model, or loaded in a  
lib/file.rb . This also includes having no validation code, and just  
placing “validates\_anything\_not\_standard :anything” call in my model.  
I’ve seen a few other posts about similar problems, but nothing  
conclusive. Why would this happen only when in the production  
environment, and not in development?

Rails 2.2.2, Ruby 1.8.6, Will-Paginate 2.3.6.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [January 15, 2009, 11:24am UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770/2 "2009-01-15T11:24:02Z")

</div>

On Jan 15, 4:00 am, Richard S. \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> This includes having the validation in my model, or loaded in a  
> lib/file.rb . This also includes having no validation code, and just  
> placing “validates\_anything\_not\_standard :anything” call in my model.  
> I’ve seen a few other posts about similar problems, but nothing  
> conclusive. Why would this happen only when in the production  
> environment, and not in development?

My hunch would be because of

> **[environment.rb and requiring dependencies - Space Vatican](https://www.spacevatican.org/2008/11/21/environment-rb-and-requiring-dependencies/)**
>
> In the before time, the bottom of most of my apps’ environment.rb was an unholy mess. Inflector rules, requiring of various libraries or gems, …

Fred

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [January 15, 2009, 5:32pm UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770/3 "2009-01-15T17:32:06Z")

</div>

You were right.

When i turned of config.cache\_classes in my environments/production.rb  
everything worked great. Of course I cant run a deployment like that,  
sooo…i moved my " require ‘custom\_validations’ " into my model  
right above my validation call, to ensure it gets loaded in the right  
order. I’m not sure how kosher this is, but it fixed the problem.

models/phrase.rb:  
…  
require 'custom\_validations  
validates\_not\_spam :word  
…

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [January 15, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770/4 "2009-01-15T18:13:15Z")

</div>

On 15 Jan 2009, at 16:32, Richard S. wrote:

> You were right.
> 
> When i turned of config.cache\_classes in my environments/production.rb  
> everything worked great. Of course I cant run a deployment like that,  
> sooo…i moved my " require ‘custom\_validations’ " into my model  
> right above my validation call, to ensure it gets loaded in the right  
> order. I’m not sure how kosher this is, but it fixed the problem.

Personally my preferred solution is what is outline in the blog post:  
have an initializer that requires stuff like that’

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [January 15, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/method-missing-only-in-production-using-custom-validation/157770/5 "2009-01-15T20:46:46Z")

</div>

Guess i’m just dense, that worked great too. I had never used  
initalizers/ before except to regulate inflections, just created an  
Application.rb and threw in my

require ‘custom\_validations’

Thanks Fred!!
