Method_missing only in production using custom validation


#1

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

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.


#2

On Jan 15, 4:00 am, Richard S. <rails-mailing-l…@andreas-
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
http://www.spacevatican.org/2008/11/21/environment-rb-and-requiring-dependencies

Fred


#3

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


#4

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’


#5

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