Method: EffectiveResourcesHelper#tableize_hash
- Defined in:
- app/helpers/effective_resources_helper.rb
#tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true) ⇒ Object
Tableize attributes This is used by effective_orders, effective_logging, effective_trash and effective_mergery
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'app/helpers/effective_resources_helper.rb', line 228 def tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true) case obj when Hash if flatten && obj[:attributes].kind_of?(Hash) obj = obj[:attributes].merge(obj.except(:attributes)) end content_tag(:table, class: table.presence) do content_tag(:tbody) do obj.map do |key, value| content_tag(:tr, class: key.to_param) do content_tag((th == true ? :th : :td), key) + content_tag(:td) { tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) } end end.join.html_safe end end when Array obj.map { |value| tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) }.join('<br>') when Symbol ":#{obj}" when NilClass '-' else obj.to_s.presence || '""' end.html_safe end |