3

I have a custom validator dimensions_validator in app/validators.

Works fine in the app in development. But when I bring up the rails console and try to load that model, PngPic.count, I get ArgumentError: Unknown validator: 'DimensionsValidator'. What gives? How is the console different than the WEBrick server?

I've restarted the console a few times, no luck.

bevanb
  • 8,201
  • 10
  • 53
  • 90
  • Is your `validators` folder in autoload paths? – BroiSatse Aug 05 '15 at 11:44
  • @Broi Pretty sure, since the validator is actually working on localhost:3000. Haven't specifically added it, as apparently the app/validators folder is automatically added. – bevanb Aug 05 '15 at 11:45
  • 1
    Might be that your server loaded it before (maybe there is a require in some other model) so it is not raising anything but the console has no idea where it is. Try adding it in application.rb and restart the console. – BroiSatse Aug 05 '15 at 11:46
  • That worked, had to explicitly add it, which is going against what I'd read. `config.autoload_paths += %W["#{config.root}/app/validators/"]`. Feel free to add that as a solution. – bevanb Aug 05 '15 at 16:23

1 Answers1

0

You can check it out this threads and compare with your own.

Rails 3, Unknown validator: 'EmailValidator'

Where should Rails 3 custom validators be stored?

Community
  • 1
  • 1
Nivla
  • 35
  • 6