I'm trying to use custom validator with my Rails 3 app. Here are my files:
app/validators/video_validator.rb
class VideoValidator < ActiveModel::Validator
def validate(record)
videoInfo = VideoInfo.new(record.video_url)
if !videoInfo.valid?
record.errors[:base] << "Some error message."
end
end
end
app/models/user_video.rb
class UserVideo < ActiveRecord::Base
validates_with VideoValidator
end
And now, when i'm trying to reach a new action from user_videos scaffolded controller, all i'm getting is this error:
Routing Error uninitialized constant UserVideo::VideoValidator
I've seend a lot of tutorials on how to create custom validators and i still can't find what have i done wrong. I'll be grateful for any tips and advices :)
is the validator path configured in autoload config. You can take a look here Rails 3 Custom Validator Problem.
Also make sure to restart your server :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With