summaryrefslogtreecommitdiff
path: root/app/models/page.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/page.rb')
-rw-r--r--app/models/page.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index 5c93a93b..e2cbee5b 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -5,10 +5,6 @@ class Page < ActiveRecord::Base
5 PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) 5 PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public))
6 FULL_PUBLIC_TEMPLATE_PATH = Rails.root.join('app', 'views', PUBLIC_TEMPLATE_PATH) 6 FULL_PUBLIC_TEMPLATE_PATH = Rails.root.join('app', 'views', PUBLIC_TEMPLATE_PATH)
7 7
8 # named scopes
9 scope :drafts, joins(:node).includes(:translations).where("nodes.draft_id = pages.id")
10 scope :heads, joins(:node).includes(:translations).where("nodes.head_id = pages.id")
11
12 # Mixins and Plugins 8 # Mixins and Plugins
13 acts_as_taggable 9 acts_as_taggable
14 acts_as_list :column => :revision, :scope => :node_id 10 acts_as_list :column => :revision, :scope => :node_id
@@ -20,16 +16,17 @@ class Page < ActiveRecord::Base
20 belongs_to :user 16 belongs_to :user
21 belongs_to :editor, :class_name => "User" 17 belongs_to :editor, :class_name => "User"
22 has_many :related_assets 18 has_many :related_assets
23 has_many :assets, :through => :related_assets, :order => "position ASC" 19 has_many :assets, -> { order("position ASC") }, :through => :related_assets
20
21 # Named scopes
22 scope :drafts, -> { joins(:node).includes(:translations).where("nodes.draft_id = pages.id") }
23 scope :heads, -> { joins(:node).includes(:translations).where("nodes.head_id = pages.id") }
24 24
25 # Filter 25 # Filter
26 before_create :set_page_title 26 before_create :set_page_title
27 before_create :set_template 27 before_create :set_template
28 before_save :rewrite_links_in_body 28 before_save :rewrite_links_in_body
29 29
30 # Security
31 attr_accessible :title, :abstract, :body, :template_name, :published_at, :user_id
32
33 # Class Methods 30 # Class Methods
34 31
35 # This method is most likely called from the ContentHelper.render_collection 32 # This method is most likely called from the ContentHelper.render_collection
@@ -146,7 +143,7 @@ class Page < ActiveRecord::Base
146 143
147 # Clone translated attributes 144 # Clone translated attributes
148 page.translations.each do |translation| 145 page.translations.each do |translation|
149 self.translations.create!(translation.attributes) 146 self.translations.create!(translation.attributes.except("id", "page_id", "created_at", "updated_at"))
150 end 147 end
151 148
152 # Clone asset references 149 # Clone asset references