Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails can't see my custom validator

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 :)

like image 608
mbajur Avatar asked Oct 26 '25 09:10

mbajur


1 Answers

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 :)

like image 188
Samiron Avatar answered Oct 28 '25 00:10

Samiron