views:

114

answers:

1

Hi, is it possible to use validations like:

class Post < ActiveRecord::Base
  validates_presence_of :name, :title  
  validates_length_of :title, :minimum => 5 
end

with basic_model?

I tried reading the source, but I couldn't find anything there. Are those validates_ available for other model types, or only ActiveRecord::Base?

Thanks a lot!

+2  A: 

The validations in ActiveRecord are very coupled with ActiveRecord itself, so you won't be able to easely use AR's validation code outside of AR. They're well aware of this, and Rails 3.0 will have ActiveModel, which decouples it from ActiveRecord, so that you could have done something like this:

class Foo
  include ActiveModel::Validations
end

Until then, you could write your own or use the validatable gem.

August Lilleaas
Thanks a lot for the answer!