From 96a928cdfd6854a168d6328bcf29096403e556db Mon Sep 17 00:00:00 2001 From: hukl Date: Fri, 4 Sep 2009 22:34:55 +0200 Subject: moved the image sorting into the model and wrapped it into a transaction --- app/controllers/pages_controller.rb | 8 +------- app/models/page.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4b3b541..6e826c0 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -16,13 +16,7 @@ class PagesController < ApplicationController def sort_images page = Page.find(params[:id]) - - page.related_assets.destroy_all - - params[:images].each_with_index do |id, index| - asset = Asset.find(id) - page.related_assets.create(:asset_id => asset.id, :position => index+1) - end + page.update_assets(params[:images]) render :nothing => true, :status => 200 end diff --git a/app/models/page.rb b/app/models/page.rb index 6b3799b..8583071 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -172,6 +172,19 @@ class Page < ActiveRecord::Base end end + def update_assets image_ids + + transaction do + self.related_assets.delete_all + + image_ids.each_with_index do |id, index| + asset = Asset.find(id) + self.related_assets.create!(:asset_id => asset.id, :position => index+1) + end + end + + end + private def set_page_title @@ -188,6 +201,13 @@ class Page < ActiveRecord::Base xml_doc = xml_string.parse links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") locales = I18n.available_locales.reject {|l| l == :root} + + if xml_doc.find("//p/aggregate")[0] + aggregate_tags = xml_doc.find("//aggregate") + aggregate_tags[0].parent.replace_with aggregate_tags[0] + end + + links.each do |link| unless locales.include? link[:href].slice(1,2).to_sym -- cgit v1.3