Sha256: fa2b32ee8d9713f901b9ea6d1a87dde45cc685893cbdd6256eb46ccb41fce1d0

Contents?: true

Size: 921 Bytes

Versions: 6

Compression:

Stored size: 921 Bytes

Contents

class Album < ActiveRecord::Base
	
	has_many :photos, :dependent => :destroy
	
	validates_presence_of :title
	validates_presence_of :filename
	validates_uniqueness_of :filename
	
	def self.page(search, page)
			paginate :per_page => 10, :page => page,
               :order => 'title',
               :conditions => ["title LIKE ?", "%#{search}%"]
  end

	has_one :menu_item, :as => :linkable, :dependent => :destroy
	
	after_create :create_menu_item
	after_update :update_menu_item
	
	def update_menu_item
		@menu_item = self.menu_item
		if @menu_item == nil
			self.create_menu_item
		else
		@menu_item.update_attributes(	
				:title => self.nav,
				:url => "/photos-for/#{self.filename}",
				:active => self.active
		)
		end
	end
	
	def create_menu_item
		@menu_item = self.build_menu_item(
			:title => self.nav,
			:url => "/photos-for/#{self.filename}",
			:active => self.active
		)
		@menu_item.save
	end
	
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dust-generators-0.1.9 rails_generators/dust_albums/templates/app/models/album.rb
dust-generators-0.1.8 rails_generators/dust_albums/templates/app/models/album.rb
dust-generators-0.1.7 rails_generators/dust_albums/templates/app/models/album.rb
dust-generators-0.1.6 rails_generators/dust_albums/templates/app/models/album.rb
dust-generators-0.1.5 rails_generators/dust_albums/templates/app/models/album.rb
dust-generators-0.1.4 rails_generators/dust_albums/templates/app/models/album.rb