Class: ContentsCore::ItemString
- Inherits:
-
Item
- Object
- ActiveRecord::Base
- ApplicationRecord
- Item
- ContentsCore::ItemString
- Defined in:
- app/models/contents_core/item_string.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#init ⇒ Object
validate :on_validate.
-
#update_data(value) ⇒ Object
def on_validate if self.block.validations if self.block.validations == ‘required’ self.errors.add( :base, “#selfself.name is required” ) if self.data_string.blank? end end end.
Methods inherited from Item
#as_json, #attr_id, #class_name, #config, #data_type, #editable, #on_after_initialize, #on_before_create, #opt_input, #process_data, #set, #to_s, types, #validate_item
Class Method Details
.permitted_attributes ⇒ Object
25 26 27 |
# File 'app/models/contents_core/item_string.rb', line 25 def self.permitted_attributes [ :data_string ] end |
.type_name ⇒ Object
29 30 31 |
# File 'app/models/contents_core/item_string.rb', line 29 def self.type_name 'string' end |
Instance Method Details
#init ⇒ Object
validate :on_validate
7 8 9 10 |
# File 'app/models/contents_core/item_string.rb', line 7 def init self.data = '' unless self.data # self.name.gsub( /-/, ' ' ).humanize self end |
#update_data(value) ⇒ Object
def on_validate
if self.block.validations[self.name]
if self.block.validations[self.name] == 'required'
self.errors.add( :base, "#{self.name} is required" ) if self.data_string.blank?
end
end
end
20 21 22 23 |
# File 'app/models/contents_core/item_string.rb', line 20 def update_data( value ) self.data = ActionController::Base.helpers.sanitize( value, tags: [] ) self.save end |