Class: SimpleBlock
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SimpleBlock
- Includes:
- Checkable, RequiredUniqueName, RequiredUniqueSlug, Toggleable
- Defined in:
- app/models/simple_block.rb
Overview
Model for simple editable block
Attributes:
background_image [Boolean]
body [Text], optional
created_at [DateTime]
image [SimpleImageUploader], optional
image_alt_text [String], optional
name [String]
slug [String]
updated_at [DateTime]
visible [Boolean]
Constant Summary collapse
- BODY_LIMIT =
65_535
- META_LIMIT =
255
- NAME_LIMIT =
100
- SLUG_LIMIT =
30
- SLUG_PATTERN =
/\A[a-z][-_a-z0-9]*[a-z0-9]\z/.freeze
- SLUG_PATTERN_HTML =
'^[a-zA-Z][-_a-zA-Z0-9]*[a-zA-Z0-9]$'
Class Method Summary collapse
-
.[](slug) ⇒ String
Get body of visible block with given slug or empty string.
- .entity_parameters ⇒ Object
- .for_visitors(slug) ⇒ Object
- .partial(slug) ⇒ Object
Class Method Details
.[](slug) ⇒ String
Get body of visible block with given slug or empty string
Can be used in views for quick output
63 64 65 |
# File 'app/models/simple_block.rb', line 63 def self.[](slug) SimpleBlock.visible.find_by(slug: slug)&.body.to_s end |
.entity_parameters ⇒ Object
43 44 45 |
# File 'app/models/simple_block.rb', line 43 def self.entity_parameters %i[body image image_alt_text name slug] + toggleable_attributes end |
.for_visitors(slug) ⇒ Object
53 54 55 |
# File 'app/models/simple_block.rb', line 53 def self.for_visitors(slug) visible.find_by(slug: slug) end |
.partial(slug) ⇒ Object
48 49 50 |
# File 'app/models/simple_block.rb', line 48 def self.partial(slug) for_visitors(slug) || 'simple_blocks/empty' end |