photomix/app/models/collection.rb

27 lines
670 B
Ruby
Raw Normal View History

2009-06-03 01:33:39 +02:00
class Collection < ActiveRecord::Base
2012-07-24 23:26:16 +02:00
extend Ext::GroupFor
2012-07-26 22:26:23 +02:00
ajaxful_rateable :stars => 5, :cache_column => :rating_average
2009-06-03 01:33:39 +02:00
has_many :collection_albums
has_many :albums, :through => :collection_albums
attr_accessor :album_list
2009-06-03 01:33:39 +02:00
2010-12-13 05:17:49 +01:00
validates :title, :presence => true
2012-07-29 00:33:03 +02:00
scope :visible, where(:public => true)
scope :popular, lambda{visible.includes(:albums => :photos).where("photos.id NOT NULL").order('collections.rating_average desc')}
def photos_count
self.albums.includes(:photos).size
end
2012-07-24 23:26:16 +02:00
2009-06-11 13:05:09 +02:00
def to_param
2009-06-16 01:18:42 +02:00
"#{id}-#{title.parameterize}"
2009-06-11 13:05:09 +02:00
end
def album_list=(albums)
self.albums = Album.find(albums.map{|album|album[0]})
end
2009-06-11 13:05:09 +02:00
end