Tuesday, May 3, 2011

Is it possible to have validations for basic_model (couchdb) in Ruby on Rails?

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!

From stackoverflow
  • 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.

    : Thanks a lot for the answer!

0 comments:

Post a Comment