photomix/app/models/tag.rb

25 lines
456 B
Ruby
Raw Normal View History

2009-05-22 22:38:52 +02:00
class Tag < ActiveRecord::Base
has_many :photo_tags
has_many :photos, :through => :photo_tags
2009-05-25 21:39:43 +02:00
validates_uniqueness_of :title
2009-06-03 21:30:09 +02:00
before_validation :downcase_title
2009-06-02 00:08:57 +02:00
def self.tag_list
return self.find(:all).map { |tag| tag.title }.join('\',\'')
end
2009-05-25 21:39:43 +02:00
def to_param
2009-06-11 13:05:09 +02:00
#id.to_s+'-'+
title.downcase.gsub(/[^a-z0-9]+/i, '-')
2009-05-25 21:39:43 +02:00
end
2009-06-03 21:30:09 +02:00
protected
def downcase_title
self.title.downcase! if attribute_present?("title")
end
2009-05-22 22:38:52 +02:00
end