Method: Toolbox::Renderer#value
- Defined in:
- lib/toolbox/rendering.rb
#value(rec) ⇒ Object
Get the field value out of a model object If the attribute method is defined and it’s a symbol, this method is called on the model object If the attribute method is defined and it’s a block (Proc), the block is called with the model object as parameter In all other cases, the field name is interpreted as method and called on the model object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/toolbox/rendering.rb', line 33 def value(rec) val = rec.send(@widget_config.model_method) if @widget_config.model_method && @widget_config.model_method.is_a?(Symbol) val = @widget_config.model_method.call(rec) if @widget_config.model_method && @widget_config.model_method.is_a?(Proc) unless val # fallback a = @widget_config.name.to_s.split('.') a.each do |t| rec = rec.send(t) break unless rec # stop if nil is returned end val = rec end val = nil if val == '' val end |