Class: Interview::AssociationAttribute

Inherits:
Attribute show all
Defined in:
lib/interview/association_attribute.rb

Instance Attribute Summary collapse

Attributes inherited from Attribute

#align, #caption, #hide_caption, #hide_tooltip, #html_class, #link, #method, #nil_value, #on_changed, #only_for, #style, #surrounding_tag

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods inherited from Attribute

#initialize, #render, #tooltip, #value

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #render, #set_attributes, #set_defaults

Constructor Details

This class inherits a constructor from Interview::Attribute

Instance Attribute Details

#association_classObject

Returns the value of attribute association_class.



4
5
6
# File 'lib/interview/association_attribute.rb', line 4

def association_class
  @association_class
end

Instance Method Details

#render_readObject



6
7
8
9
10
11
12
13
# File 'lib/interview/association_attribute.rb', line 6

def render_read
  return '' if value.nil?
  assoc_object = value
  # todo: Link nicht anzeigen, wenn Route für Objekt nicht existiert
  return Link.new(parent: self,
                  caption: "#{assoc_object.human_id}",
                  object: assoc_object).render
end

#render_writeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/interview/association_attribute.rb', line 15

def render_write
  object = find_attribute!(:object)
  if object.respond_to? "#{method}_pool"
    pool = object.send "#{method}_pool"
  elsif @association_class
    assoc_class = Object.const_get(@association_class.to_s.camelcase)
    pool = assoc_class.all
  else
    assoc_class = object.class.new.send("build_#{@method}").class
    pool = assoc_class.all
  end
  form_builder.collection_select "#{@method}_id", pool, :id, :human_id, {include_blank: true}, {class: 'form-control'}
  # todo: prompt einbauen
end