Class: Dhatu::Page
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dhatu::Page
- Includes:
- Publishable
- Defined in:
- app/models/dhatu/page.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
-
#display_name ⇒ Object
Generic Methods —————.
Class Method Details
.save_row_data(hsh) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/dhatu/page.rb', line 27 def self.save_row_data(hsh) # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new return error_object if hsh[:code].to_s.strip.blank? page = Dhatu::Page.where("code = ?", hsh[:code].to_s.strip).first || Dhatu::Page.new page.name = hsh[:name].to_s.strip page.code = hsh[:code].to_s.strip page.feature = Feature.where("name = ?", hsh[:feature].to_s.strip).first page.status = hsh[:status].to_s.strip || PUBLISHED page.priority = hsh[:priority].to_s.strip || 1 if page.valid? begin page.save! rescue Exception => e summary = "uncaught #{e} exception while handling connection: #{e.}" details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}" error_object.errors << { summary: summary, details: details } end else summary = "Error while saving page: #{page.title}" details = "Error! #{page.errors..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
77 78 79 80 |
# File 'app/models/dhatu/page.rb', line 77 def can_be_deleted? return false if self.sections.count > 0 status?(:removed) end |
#can_be_edited? ⇒ Boolean
Permission Methods
73 74 75 |
# File 'app/models/dhatu/page.rb', line 73 def can_be_edited? status?(:published) or status?(:unpublished) end |
#display_name ⇒ Object
Generic Methods
66 67 68 |
# File 'app/models/dhatu/page.rb', line 66 def display_name "#{self.name_was} - #{self.code}" end |