Class: Decidim::StaticPage

Inherits:
ApplicationRecord show all
Includes:
Loggable, Traceable, TranslatableResource
Defined in:
app/models/decidim/static_page.rb

Overview

A page is used to add static content to the website, it can be useful so organization can add their own terms and conditions, privacy policy or other pages they might need from an admin panel.

Pages with a default slug cannot be destroyed and its slug cannot be modified.

Constant Summary collapse

DEFAULT_PAGES =

These pages will be created by default when registering an organization and cannot be deleted.

%w(terms-and-conditions).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default?(slug) ⇒ Boolean

Whether this is slug of a default page or not.

slug - The String with the value of the slug.

Returns Boolean.

Returns:

  • (Boolean)


38
39
40
# File 'app/models/decidim/static_page.rb', line 38

def self.default?(slug)
  DEFAULT_PAGES.include?(slug)
end

.log_presenter_class_for(_log) ⇒ Object



42
43
44
# File 'app/models/decidim/static_page.rb', line 42

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::StaticPagePresenter
end

.sorted_by_i18n_title(locale = I18n.locale) ⇒ Object



46
47
48
# File 'app/models/decidim/static_page.rb', line 46

def self.sorted_by_i18n_title(locale = I18n.locale)
  order([Arel.sql("title->? ASC"), locale])
end

Instance Method Details

#default?Boolean

Whether this is page is a default one or not.

Returns Boolean.

Returns:

  • (Boolean)


53
54
55
# File 'app/models/decidim/static_page.rb', line 53

def default?
  self.class.default?(slug)
end

#to_paramObject

Customize to_param so when we want to create a link to a page we use the slug instead of the id.

Returns a String.



61
62
63
# File 'app/models/decidim/static_page.rb', line 61

def to_param
  slug
end