summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-09-04 22:34:55 +0200
committerhukl <contact@smyck.org>2009-09-04 22:34:55 +0200
commit96a928cdfd6854a168d6328bcf29096403e556db (patch)
tree4ccdabb8f5186d355bf395772addfbd6afabc8ef /app/models
parentfed65d37b7894d7cccbe44757148c5441af90cc3 (diff)
moved the image sorting into the model and wrapped it into a transaction
Diffstat (limited to 'app/models')
-rw-r--r--app/models/page.rb20
1 files changed, 20 insertions, 0 deletions
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
172 end 172 end
173 end 173 end
174 174
175 def update_assets image_ids
176
177 transaction do
178 self.related_assets.delete_all
179
180 image_ids.each_with_index do |id, index|
181 asset = Asset.find(id)
182 self.related_assets.create!(:asset_id => asset.id, :position => index+1)
183 end
184 end
185
186 end
187
175 private 188 private
176 189
177 def set_page_title 190 def set_page_title
@@ -188,6 +201,13 @@ class Page < ActiveRecord::Base
188 xml_doc = xml_string.parse 201 xml_doc = xml_string.parse
189 links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") 202 links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]")
190 locales = I18n.available_locales.reject {|l| l == :root} 203 locales = I18n.available_locales.reject {|l| l == :root}
204
205 if xml_doc.find("//p/aggregate")[0]
206 aggregate_tags = xml_doc.find("//aggregate")
207 aggregate_tags[0].parent.replace_with aggregate_tags[0]
208 end
209
210
191 211
192 links.each do |link| 212 links.each do |link|
193 unless locales.include? link[:href].slice(1,2).to_sym 213 unless locales.include? link[:href].slice(1,2).to_sym