2009-05-22 22:38:52 +02:00
|
|
|
class Tag < ActiveRecord::Base
|
2009-08-11 01:23:30 +02:00
|
|
|
has_many :photo_tags, :dependent => :destroy
|
2009-05-22 22:38:52 +02:00
|
|
|
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-08-11 01:23:30 +02:00
|
|
|
"#{id}-#{title.parameterize}"
|
|
|
|
end
|
2009-05-25 21:39:43 +02:00
|
|
|
|
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
|