Update validates for Rails 3

master
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 :collections, :through => :collection_albums
validates_uniqueness_of :path, :message => "Album already exsists on disc"
validates_presence_of :title, :message => "can't be blank"
validates :path, :presence => true, :uniqueness => true, :message => "Album already exsists on disc"
validates :title, :presence => true, :message => "can't be blank"
before_validation :ensure_path, :set_title
after_create :create_folders
@ -13,22 +13,20 @@ class Album < ActiveRecord::Base
attr_accessor :tags
#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 :unused, :conditions => "albums.id NOT IN (SELECT album_id FROM collection_albums)"
scope :used, :conditions => "albums.id IN (SELECT album_id FROM collection_albums)"
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, where("albums.id NOT IN (SELECT album_id FROM collection_albums)")
scope :used, where("albums.id IN (SELECT album_id FROM collection_albums)")
def to_param
"#{id}-#{title.parameterize}"
end
def ensure_path
self.path = self.title.parameterize unless self.path
end
def set_title
self.title = File.basename( self.path).titleize unless self.title || !self.path
self.title = File.basename(self.path).titleize unless self.title || !self.path
end
def tags

View File

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

View File

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

View File

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