Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has "def validate" been taken out in Rails 3.1?

Has "def validate" been taken out in Rails 3.1? I'm on Rails 3.1 pre and it doesn't seem to be working

class Category < ActiveRecord::Base
  validates_presence_of :title

  private 

  def validate
    errors.add(:description, "is too short") if (description.size < 200)
  end 
end

The "title" validation works but the "description" validation doesn't.

like image 394
vince Avatar asked Dec 12 '22 10:12

vince


1 Answers

Does something like this work for you?

class Category < ActiveRecord::Base
  validates_presence_of :title
  validate :description_length

  def description_length
    errors.add(:description, "is too short") if (description.size < 200)
  end 
end
like image 194
Devin M Avatar answered Dec 25 '22 20:12

Devin M