From 1d7a814fb1a2e7725bc142dfbf9501cfd909c781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 3 Dec 2010 10:55:09 +0200 Subject: Rails 3 validation style. --- app/models/blog_category.rb | 3 +-- app/models/blog_comment.rb | 5 ++--- app/models/blog_post.rb | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb index 89bff27..6d5e886 100644 --- a/app/models/blog_category.rb +++ b/app/models/blog_category.rb @@ -4,8 +4,7 @@ class BlogCategory < ActiveRecord::Base acts_as_indexed :fields => [:title] - validates_presence_of :title - validates_uniqueness_of :title + validates :title, :presence => true, :uniqueness => true has_friendly_id :title, :use_slug => true diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index f608a1a..8ab1cf3 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -10,9 +10,8 @@ class BlogComment < ActiveRecord::Base alias_attribute :message, :body - validates_presence_of :name, :message - validates_format_of :email, - :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i + validates :name, :message, :presence => true + validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } scope :unmoderated, :conditions => {:state => nil} scope :approved, :conditions => {:state => 'approved'} diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 8937e09..f2a1465 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -5,8 +5,7 @@ class BlogPost < ActiveRecord::Base acts_as_indexed :fields => [:title, :body] - validates_presence_of :title - validates_uniqueness_of :title + validates :title, :presence => true, :uniqueness => true has_friendly_id :title, :use_slug => true -- cgit v1.2.3