Update validates for Rails 3

This commit is contained in:
Rémi Vanicat 2010-12-13 05:17:49 +01:00
parent de0842d203
commit 9e657dc110
4 changed files with 11 additions and 12 deletions

View file

@ -3,8 +3,8 @@ class Album < ActiveRecord::Base
has_many :collection_albums has_many :collection_albums
has_many :collections, :through => :collection_albums has_many :collections, :through => :collection_albums
validates_uniqueness_of :path, :message => "Album already exsists on disc" validates :path, :presence => true, :uniqueness => true, :message => "Album already exsists on disc"
validates_presence_of :title, :message => "can't be blank" validates :title, :presence => true, :message => "can't be blank"
before_validation :ensure_path, :set_title before_validation :ensure_path, :set_title
after_create :create_folders after_create :create_folders
@ -13,16 +13,14 @@ class Album < ActiveRecord::Base
attr_accessor :tags attr_accessor :tags
#attr_protected :path #attr_protected :path
scope :untouched, :conditions => "albums.id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description IS NULL AND photos.id NOT IN ( SELECT photo_id FROM photo_tags) )", :order => 'title' scope :untouched, where("albums.id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description IS NULL AND photos.id NOT IN ( SELECT photo_id FROM photo_tags) )").order('title')
scope :unused, :conditions => "albums.id NOT IN (SELECT album_id FROM collection_albums)" scope :unused, where("albums.id NOT IN (SELECT album_id FROM collection_albums)")
scope :used, :conditions => "albums.id IN (SELECT album_id FROM collection_albums)" scope :used, where("albums.id IN (SELECT album_id FROM collection_albums)")
def to_param def to_param
"#{id}-#{title.parameterize}" "#{id}-#{title.parameterize}"
end end
def ensure_path def ensure_path
self.path = self.title.parameterize unless self.path self.path = self.title.parameterize unless self.path
end end

View file

@ -3,6 +3,8 @@ class Collection < ActiveRecord::Base
has_many :albums, :through => :collection_albums has_many :albums, :through => :collection_albums
attr_accessor :album_list attr_accessor :album_list
validates :title, :presence => true
def to_param def to_param
"#{id}-#{title.parameterize}" "#{id}-#{title.parameterize}"
end end

View file

@ -5,8 +5,8 @@ class Photo < ActiveRecord::Base
mount_uploader :file, FileUploader mount_uploader :file, FileUploader
#validates_uniqueness_of :path, :message => "Photo already exsists on disc" validates :path, :presence => true, :uniqueness => true, :message => "Photo already exsists on disc"
validates_presence_of :title validates :title, :presence => true
before_validation :set_title before_validation :set_title
#before_create :exif_read #before_create :exif_read
@ -87,5 +87,4 @@ class Photo < ActiveRecord::Base
photo.save photo.save
end end
end end

View file

@ -6,7 +6,7 @@ class Role < ActiveRecord::Base
has_many :subroles, :through => :roleables, :source => :roleable, :source_type => 'Role' has_many :subroles, :through => :roleables, :source => :roleable, :source_type => 'Role'
has_many :users, :through => :roleables, :source => :roleable, :source_type => 'User' has_many :users, :through => :roleables, :source => :roleable, :source_type => 'User'
validates_uniqueness_of :name validates :name, :presence => true, :uniqueness => true
acts_as_permissible acts_as_permissible
end end