ruby rocks
This commit is contained in:
parent
1ae1716a0b
commit
91a3662a19
|
@ -44,11 +44,11 @@ class Album < ActiveRecord::Base
|
|||
tags = tags & photo_tags
|
||||
end
|
||||
}
|
||||
return tags.collect{|tag| tag.title }.join(" ")
|
||||
return tags.collect{|tag| tag.title }.sort.join(" ")
|
||||
end
|
||||
|
||||
def tag_list=(tags)
|
||||
return if tags == self.tag_list
|
||||
return if tags.split(" ").sort.join(" ") == self.tag_list
|
||||
current_tags = self.tag_list.split(" ")
|
||||
tags = tags.split(" ")
|
||||
|
||||
|
@ -58,8 +58,7 @@ class Album < ActiveRecord::Base
|
|||
(current_tags - tags).each { |tag|
|
||||
#puts "remove #{tag}"
|
||||
self.photos.each {|photo|
|
||||
#TODO in photo model
|
||||
#photo.tag_remove( tag )
|
||||
photo.untag( tag )
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,8 +66,7 @@ class Album < ActiveRecord::Base
|
|||
tags.each do |tag|
|
||||
#puts "tag photos with #{tag}" if !current_tags.include?( tag )
|
||||
self.photos.each { |photo|
|
||||
#TODO in photo model
|
||||
#photo.tag_with( tag ) if !current_tags.include?( tag ) # no need to re-tag
|
||||
photo.tag( tag ) if !current_tags.include?( tag ) # no need to re-tag
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,9 +22,6 @@ class Photo < ActiveRecord::Base
|
|||
self.find(:all, :conditions => "Photos.description IS NULL AND Photos.Id NOT IN ( SELECT Photo_ID FROM Photo_Tags)", :include => :album )
|
||||
end
|
||||
|
||||
def extension
|
||||
return File.extname(self.path_original)
|
||||
end
|
||||
|
||||
def path_original_public
|
||||
return APP_CONFIG[:photos_path_public] + self.path
|
||||
|
@ -34,6 +31,21 @@ class Photo < ActiveRecord::Base
|
|||
return APP_CONFIG[:thumbs_path_public] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
||||
end
|
||||
|
||||
def tag(title)
|
||||
return if self.tags.collect{|tag|tag.title}.include?( title )
|
||||
self.photo_tags.create(:tag => Tag.find_or_create_by_title( :title => title) )
|
||||
self.reload
|
||||
end
|
||||
|
||||
def untag(title)
|
||||
return if !self.tags.collect{|tag|tag.title}.include?( title )
|
||||
# perhaps not the best way but it finds the correct PhotoTag and deletes it
|
||||
self.photo_tags.select{|photo_tag|
|
||||
photo_tag.tag.title == title
|
||||
}.each {|photo_tag|photo_tag.destroy}
|
||||
self.reload
|
||||
end
|
||||
|
||||
|
||||
def tag_list
|
||||
return self.tags.find(:all, :order => 'title').collect{ |t| t.title }.join(" ")
|
||||
|
@ -67,6 +79,11 @@ class Photo < ActiveRecord::Base
|
|||
|
||||
protected
|
||||
|
||||
|
||||
def extension
|
||||
return File.extname(self.path_original)
|
||||
end
|
||||
|
||||
def path_original
|
||||
return APP_CONFIG[:photos_path] + self.path
|
||||
end
|
||||
|
@ -75,9 +92,9 @@ class Photo < ActiveRecord::Base
|
|||
return APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def create_thumbnails
|
||||
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
|
||||
#puts " thumbing it..thumbing it.."
|
||||
|
|
Loading…
Reference in a new issue