Module: ScaffoldingExtensions::Model

Included in:
ActiveRecord::Base, Sequel::Model
Defined in:
lib/scaffolding_extensions/model.rb

Overview

Instance methods shared by all models

Instance Method Summary collapse

Instance Method Details

#scaffold_error_messagesObject

an array of strings describing problems with the object (empty if none)



4
5
6
# File 'lib/scaffolding_extensions/model.rb', line 4

def scaffold_error_messages
  errors.full_messages
end

#scaffold_nameObject

The name given to the item that is used in various places in the scaffold. For example, it is used whenever the record is displayed in a select box. Should be unique for each record, but that is not required. Should be overridden by subclasses unless they have a unique attribute named ‘name’.



12
13
14
# File 'lib/scaffolding_extensions/model.rb', line 12

def scaffold_name
  scaffold_attribute_value(:name) || scaffold_id.to_s
end

#scaffold_name_with_idObject

scaffold_name prefixed with id, used for scaffold autocompleting



17
18
19
# File 'lib/scaffolding_extensions/model.rb', line 17

def scaffold_name_with_id
  "#{scaffold_id} - #{scaffold_name}"
end

#scaffold_value(field) ⇒ Object

the value of the field if not an association, or the scaffold_name of the associated object



22
23
24
25
26
27
28
29
# File 'lib/scaffolding_extensions/model.rb', line 22

def scaffold_value(field)
  if self.class.scaffold_association(field)
    obj = send(field) 
    obj.scaffold_name if obj
  else
    send(field)
  end
end