Created
March 31, 2013 22:27
-
-
Save Siron/5282262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Refinery | |
module PhotoGallery | |
module Extensions | |
module Pages | |
def has_one_page_album | |
has_many :album_page, :as => :page, :dependent=> :destroy | |
has_many :album, :through => :album_page | |
has_many :photos, :class_name => Refinery::PhotoGallery::Photo, :through => :album , :order=> "created_at ASC" | |
accepts_nested_attributes_for :album_page | |
module_eval do | |
def photos_for_page(params_page) | |
Refinery::PhotoGallery::Photo.where("album_id = ?", self.album.id ). | |
includes(:album). | |
paginate(:page => params_page). | |
order("created_at ASC") | |
end | |
def album_page=(album_page_params) | |
# new | |
if self.album_page.nil? | |
self.build_album_page | |
end | |
# destroy | |
#if album_page_params[:album_id].blank? | |
# self.album_page.destroy | |
Refinery::Admin::AlbumPageSweeper.sweep | |
# create or update if changed | |
#elsif self.album_page.album_id.to_s != album_page_params[:album_id] | |
#self.album_page.update_attributes( album_page_params) | |
#self.album_page.save | |
album_page_params.each do |album| | |
#self.album_page.build(:album_id => album[:album_id]) | |
#if self.album_page.album_id.to_s != album[:album_id] | |
# self.album_page.update_attributes(album[:album_id]) | |
# self.album_page.save | |
ap = album_page.find(album[:album_id]) || album_page.build | |
ap.attributes = album | |
ap.save | |
end | |
Refinery::Admin::AlbumPageSweeper.sweep | |
#end | |
end | |
end | |
attr_accessible :album_page | |
end | |
end | |
end | |
end | |
end | |
ActiveRecord::Base.send(:extend, Refinery::PhotoGallery::Extensions::Pages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment