diff options
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index f804353a..05abd438 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -3,23 +3,11 @@ require 'xml' | |||
| 3 | class Page < ActiveRecord::Base | 3 | class Page < ActiveRecord::Base |
| 4 | 4 | ||
| 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 = File.join(RAILS_ROOT, 'app', 'views', PUBLIC_TEMPLATE_PATH) | 6 | FULL_PUBLIC_TEMPLATE_PATH = Rails.root.join('app', 'views', PUBLIC_TEMPLATE_PATH) |
| 7 | 7 | ||
| 8 | # named scopes | 8 | # named scopes |
| 9 | 9 | scope :drafts, joins(:node).includes(:translations).where("nodes.draft_id = pages.id") | |
| 10 | named_scope( | 10 | scope :heads, joins(:node).includes(:translations).where("nodes.head_id = pages.id") |
| 11 | :drafts, | ||
| 12 | :joins => :node, | ||
| 13 | :include => [:translations], | ||
| 14 | :conditions => ["nodes.draft_id = pages.id"] | ||
| 15 | ) | ||
| 16 | |||
| 17 | named_scope( | ||
| 18 | :heads, | ||
| 19 | :joins => :node, | ||
| 20 | :include => [:translations], | ||
| 21 | :conditions => ["nodes.head_id = pages.id"] | ||
| 22 | ) | ||
| 23 | 11 | ||
| 24 | # Mixins and Plugins | 12 | # Mixins and Plugins |
| 25 | acts_as_taggable | 13 | acts_as_taggable |
| @@ -62,15 +50,16 @@ class Page < ActiveRecord::Base | |||
| 62 | 50 | ||
| 63 | options = defaults.merge options | 51 | options = defaults.merge options |
| 64 | 52 | ||
| 65 | Page.heads.paginate( | 53 | scope = Page.heads |
| 66 | find_options_for_find_tagged_with( | 54 | unless options[:tags].blank? |
| 67 | options[:tags].gsub(/\s/, ","), :match_all => true, :conditions => options[:conditions] | 55 | scope = scope.tagged_with( |
| 68 | ).merge( | 56 | options[:tags].gsub(/\s/, ",").split(",").map(&:strip), |
| 69 | :page => page, | 57 | :match_all => true |
| 70 | :per_page => options[:limit], | ||
| 71 | :order => "#{options[:order_by]} #{options[:order_direction]}" | ||
| 72 | ) | 58 | ) |
| 73 | ) | 59 | end |
| 60 | |||
| 61 | scope.order("#{options[:order_by]} #{options[:order_direction]}") | ||
| 62 | .paginate(:page => page, :per_page => options[:limit]) | ||
| 74 | end | 63 | end |
| 75 | 64 | ||
| 76 | def self.custom_templates | 65 | def self.custom_templates |
