diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 5 | ||||
| -rw-r--r-- | app/models/page.rb | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 4f585e1..70ed4da 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -22,6 +22,11 @@ class Node < ApplicationRecord | |||
| 22 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? } | 22 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? } |
| 23 | validates_presence_of :parent_id, :unless => -> { Node.root.nil? } | 23 | validates_presence_of :parent_id, :unless => -> { Node.root.nil? } |
| 24 | 24 | ||
| 25 | validates :default_template_name, | ||
| 26 | :inclusion => { :in => ->(_) { Page.custom_templates } }, | ||
| 27 | :allow_nil => true, | ||
| 28 | :if => :default_template_name_changed? | ||
| 29 | |||
| 25 | # Class methods | 30 | # Class methods |
| 26 | 31 | ||
| 27 | # Returns a page for a given node. If no revision is supplied, it returns | 32 | # Returns a page for a given node. If no revision is supplied, it returns |
diff --git a/app/models/page.rb b/app/models/page.rb index e5a8d9d..be21ff7 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -11,6 +11,16 @@ class Page < ApplicationRecord | |||
| 11 | 11 | ||
| 12 | translates :title, :abstract, :body # Globalize2 | 12 | translates :title, :abstract, :body # Globalize2 |
| 13 | 13 | ||
| 14 | # Template names render as filesystem paths; only names actually | ||
| 15 | # present in the public template directory are acceptable. Validated | ||
| 16 | # only on change so legacy rows whose template file has since | ||
| 17 | # vanished stay saveable -- valid_template already falls back to | ||
| 18 | # standard_template for those at render time. | ||
| 19 | validates :template_name, | ||
| 20 | :inclusion => { :in => ->(_) { Page.custom_templates } }, | ||
| 21 | :allow_nil => true, | ||
| 22 | :if => :template_name_changed? | ||
| 23 | |||
| 14 | # Associations | 24 | # Associations |
| 15 | belongs_to :node, optional: true | 25 | belongs_to :node, optional: true |
| 16 | belongs_to :user, optional: true | 26 | belongs_to :user, optional: true |
| @@ -77,7 +87,10 @@ class Page < ApplicationRecord | |||
| 77 | .paginate(:page => page, :per_page => options[:limit]) | 87 | .paginate(:page => page, :per_page => options[:limit]) |
| 78 | end | 88 | end |
| 79 | 89 | ||
| 80 | scope.order("#{options[:order_by]} #{direction}") | 90 | column = options[:order_by].to_s.sub(/\Apages\./, "") |
| 91 | column = "id" unless %w[id published_at created_at updated_at].include?(column) | ||
| 92 | |||
| 93 | scope.order("pages.#{column} #{direction}") | ||
| 81 | .paginate(:page => page, :per_page => options[:limit]) | 94 | .paginate(:page => page, :per_page => options[:limit]) |
| 82 | end | 95 | end |
| 83 | 96 | ||
