Class: PageTemplate
- Inherits:
-
Object
- Object
- PageTemplate
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/page_template.rb
Instance Method Summary (collapse)
-
- (Object) delete
prevent from deleting a template which is in use by a page.
-
- (Boolean) in_use?
Check if any page is using this template.
- - (Object) render(&block)
Instance Method Details
- (Object) delete
prevent from deleting a template which is in use by a page.
30 31 32 33 34 35 36 37 |
# File 'app/models/page_template.rb', line 30 def delete if self.in_use? self.errors.add(:base, I18n.translate(:template_in_use)) false else super end end |
- (Boolean) in_use?
Check if any page is using this template.
19 20 21 22 23 24 25 26 27 |
# File 'app/models/page_template.rb', line 19 def in_use? Page.all.each do |page| return true if page.page_template_id == self.id page.page_components.each do |component| return true if component.page_template_id == self.id end end false end |
- (Object) render(&block)
39 40 41 42 43 |
# File 'app/models/page_template.rb', line 39 def render(&block) "<div class='#{self.css_class}'>" + yield( self.html_template) + "</div>" end |