Class: Interview::AssociationListAttribute
- Defined in:
- lib/interview/association_list_attribute.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
-
#use ⇒ Object
Returns the value of attribute use.
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
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
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/interview/association_list_attribute.rb', line 4 def size @size end |
#use ⇒ Object
Returns the value of attribute use.
4 5 6 |
# File 'lib/interview/association_list_attribute.rb', line 4 def use @use end |
Instance Method Details
#render_read ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/interview/association_list_attribute.rb', line 6 def render_read return '' if value.nil? assoc_objects = value assoc_count = assoc_objects.count if @use == 'link' return Link.new(caption: "#{@method.humanize} (#{assoc_count})", object: "#{assoc_objects.klass}", filter: assoc_objects.where_values_hash).render # todo: Überarbeiten else return assoc_objects.human_ids.join(', ') end end |
#render_write ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/interview/association_list_attribute.rb', line 19 def render_write size = @size || 8 if @use == 'multi_select' object = find_attribute!(:object) if object.respond_to? "#{method.singularize}_pool" pool = object.send "#{method.singularize}_pool" else assoc_class = object.class.new.send(@method).build.class pool = assoc_class.all end form_builder.collection_select "#{@method.singularize}_ids", pool, :id, :human_id, {prompt: true}, {class: 'form-control', multiple: true, size: size} # form_builder.collection_select "#{@method.singularize}_ids", Category.all.collect {|x| [x.name, x.id]}, {}, :multiple => true else return form_builder.text_field "#{@method}_human_ids_string", class: 'form-control' end end |