Class: Page
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Page
- Includes:
- MarkdownBody, Searchable
- Defined in:
- app/models/page.rb
Instance Attribute Summary collapse
-
#change_desc ⇒ Object
Returns the value of attribute change_desc.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#version_enable ⇒ Object
Returns the value of attribute version_enable.
Class Method Summary collapse
Instance Method Summary collapse
- #append_editor ⇒ Object
- #as_indexed_json(_options = {}) ⇒ Object
- #create_version ⇒ Object
- #editors ⇒ Object
- #indexed_changed? ⇒ Boolean
-
#revert_version(version) ⇒ Object
撤掉到指定版本.
- #to_param ⇒ Object
Instance Attribute Details
#change_desc ⇒ Object
Returns the value of attribute change_desc.
11 12 13 |
# File 'app/models/page.rb', line 11 def change_desc @change_desc end |
#user_id ⇒ Object
Returns the value of attribute user_id.
11 12 13 |
# File 'app/models/page.rb', line 11 def user_id @user_id end |
#version_enable ⇒ Object
Returns the value of attribute version_enable.
11 12 13 |
# File 'app/models/page.rb', line 11 def version_enable @version_enable end |
Class Method Details
.find_by_slug(slug) ⇒ Object
71 72 73 |
# File 'app/models/page.rb', line 71 def self.find_by_slug(slug) fetch_by_uniq_keys(slug: slug) end |
Instance Method Details
#append_editor ⇒ Object
21 22 23 24 25 |
# File 'app/models/page.rb', line 21 def append_editor unless editor_ids.include?(user_id.to_i) editor_ids << user_id.to_i end end |
#as_indexed_json(_options = {}) ⇒ Object
46 47 48 |
# File 'app/models/page.rb', line 46 def as_indexed_json( = {}) as_json(only: [:slug, :title, :body]) end |
#create_version ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/page.rb', line 29 def create_version # 只有当 version_enable 为 true 的时候才记录版本 # 以免后台,以及其他的一些 update 时被误调用 return true unless version_enable # 只有 body, title, slug 更改了才更新版本 if self.body_changed? || self.title_changed? || self.slug_changed? update_column(:version, self.version + 1) PageVersion.create(user_id: user_id, page_id: id, desc: change_desc || '', version: version, body: body, title: title, slug: slug) end end |
#editors ⇒ Object
67 68 69 |
# File 'app/models/page.rb', line 67 def editors User.where(id: editor_ids) end |
#indexed_changed? ⇒ Boolean
50 51 52 |
# File 'app/models/page.rb', line 50 def indexed_changed? slug_changed? || title_changed? || body_changed? end |
#revert_version(version) ⇒ Object
撤掉到指定版本
59 60 61 62 63 64 65 |
# File 'app/models/page.rb', line 59 def revert_version(version) page_version = PageVersion.where(page_id: id, version: version).first return false if page_version.blank? update(body: page_version.body, title: page_version.title, slug: page_version.slug) end |
#to_param ⇒ Object
54 55 56 |
# File 'app/models/page.rb', line 54 def to_param slug end |