Class: EditableComponents::ItemString

Inherits:
Item show all
Defined in:
app/models/editable_components/item_string.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#attr_id, #class_name, #editable, item_types, #opt_input, #to_s

Class Method Details

.type_nameObject



25
26
27
# File 'app/models/editable_components/item_string.rb', line 25

def self.type_name
  'string'
end

Instance Method Details

#initObject



7
8
9
10
# File 'app/models/editable_components/item_string.rb', line 7

def init
  self.data = self.name.gsub( /-/, ' ' ).humanize
  self
end

#on_validateObject



12
13
14
15
16
17
18
# File 'app/models/editable_components/item_string.rb', line 12

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

#update_data(value) ⇒ Object



20
21
22
23
# File 'app/models/editable_components/item_string.rb', line 20

def update_data( value )
  self.data = ActionController::Base.helpers.sanitize( value, tags: [] )
  self.save
end