app/helpers/application_helper.rb
# render entity's each item(item struct) for display
render entity's each item(item struct) for display
render entity ' s each item ( item struct ) for display
def render_entity_item(entity, item)
     entity && item or fail "no item given for 'render_entity_item'" 
     name         = item.name.to_s
     model_value  = item.model_value
     template     = item.template
     options      = item.options || {}
     html_options = item.html_options || {}
     case  model_value 
       when String         
         value  = entity.send(name)  
       when Symbol, Array  
         method, *args = *model_value
         value = method == :self ? entity : entity.send(method, *args) 
       else
         fail "'#{model_value} is illegal as model value of entity item."
     end
     case template
       when nil  
         if value.is_a?(Array) 
           render_pure_collection value, :div_id => name, :entity_template =>  (template || "#{name}/entity")
         else
           value
         end
       when String  
         options ||= {}; html_options ||= {}   
         if value.is_a?(Array)
           render_pure_collection value, :div_id => name, :entity_template => template
         else
           render :partial => template, :locals => {:value => value, :options => options, :html_options => html_options}
         end
       when Symbol, Array  
         helper_method, *args = *template
         self.send(helper_method, value, *args)
       else
         fail ArgumentError, "'#{template}' is illegal as template for entity item."
      end
  end
def render_entity_item ( entity , item ) entity && item or fail "no item given for 'render_entity_item'" name = item . name . to_s model_value = item . model_value template = item . template options = item . options || { } html_options = item . html_options || { } case model_value when String value = entity . send ( name ) when Symbol , Array method , * args = * model_value value = method == :self ? entity : entity . send ( method , * args ) else fail "'#{model_value} is illegal as model value of entity item." end case template when nil if value . is_a? ( Array ) render_pure_collection value , :div_id => name , :entity_template => ( template || "#{name}/entity" ) else value end when String options ||= { } ; html_options ||= { } if value . is_a? ( Array ) render_pure_collection value , :div_id => name , :entity_template => template else render :partial => template , :locals => { :value => value , :options => options , :html_options => html_options } end when Symbol , Array helper_method , * args = * template self . send ( helper_method , value , * args ) else fail ArgumentError , "'#{template}' is illegal as template for entity item." end end
render entity's each item(item struct) for display
render entity ' s each item ( item struct ) for display
# name designates attribute of entity defined by the string( model_value ). # a method(Simbol) or  Array of a method(Symbol) and its args to apply entity. # template is omitted. # name of partial template to embed the value   # apply helper method 
entity
<not_specific>
item
<not_specific>