% excluded_columns ||= [] %>
<% additional_columns ||= [] %>
<% show_columns ||= [] %>
<% nested_resource ||= false %>
<% relationships ||= {} %>
<% box_class ||= 'primary' %>
<% hide_links ||= false %>
<% show_actions ||= ['new', 'edit', 'index'] %>
<% hide_header ||= false %>
<% hide_table_header ||= false %>
<% if show_columns.empty? %>
<% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
<% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
<% show_columns = form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns + additional_columns %>
<% end %>
<% unless hide_header %>
<% end %>
<% unless hide_table_header %>
<%= t('field') %> |
<%= t('value') %> |
<% end %>
<% show_columns.each do |column| %>
<% unless /_currency$/ =~ column %>
<% if /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
<%= object.class.human_attribute_name(column.split("_id")[0]) %>
<% elsif /_cents$/ =~ column %>
<%= object.class.human_attribute_name(column.split("_cents")[0]) %>
<% else %>
<%= object.class.human_attribute_name(column) %>
<% end %>
|
<% if column.to_s.include?('.') %>
<% o = object %>
<% column.split('.').each{|m| o = o.send(m) if o } %>
<%= o %>
<% elsif object.send(column).class == Date or
object.send(column).class == DateTime or
object.send(column).class == ActiveSupport::TimeWithZone or
object.send(column).class == Time %>
<%=l object.send(column) %>
<% elsif object.send(column).respond_to? 'attached?' %>
<% if object.send(column).class == ActiveStorage::Attached::One %>
<% if object.send(column).attached? %>
<%= link_to rails_blob_path(object.send(column)), class: "btn btn-#{box_class} btn-xs", target: '_blank' do %>
Arquivo
<% end %>
<% end %>
<% end %>
<% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
<%= object.send(column.split("_id")[0])&.name %>
<% elsif /_cents$/ =~ column %>
<%= number_to_currency object.send(column.split("_cents")[0]) %>
<% else %>
<%= object.send(column) %>
<% end %>
|
<% end %>
<% end %>
<% if relationships.any? %>
<% relationships.each do |key, value| %>
<% if object.association(key.to_s).kind_of?(ActiveRecord::Associations::BelongsToAssociation) ||
object.association(key.to_s).kind_of?(ActiveRecord::Associations::HasOneAssociation) %>
<% unless hide_table_header %>
<%= t('field') %> |
<%= t('value') %> |
<% end %>
<% value.each do |v| %>
<% if /_id$/ =~ v && Kernel.const_get(key.to_s.singularize.camelize).new.respond_to?(v.split('_id')[0]) %>
<%= Kernel.const_get(key.to_s.singularize.camelize).human_attribute_name(v.split('_id')[0]) %>
<% elsif /_cents$/ =~ v %>
<%= Kernel.const_get(key.to_s.singularize.camelize).human_attribute_name(v.split("_cents")[0]) %>
<% else %>
<%= Kernel.const_get(key.to_s.singularize.camelize).human_attribute_name(v) %>
<% end %>
|
<% if object.send(key.to_s).send(v).class == Date or
object.send(key.to_s).send(v).class == DateTime or
object.send(key.to_s).send(v).class == ActiveSupport::TimeWithZone or
object.send(key.to_s).send(v).class == Time %>
<%=l object.send(key.to_s).send(v) %>
<% elsif /_id$/ =~ v && object.send(key.to_s).respond_to?(v.split('_id')[0]) %>
<%= object.send(key.to_s).send(v.split("_id")[0])&.name %>
<% elsif /_cents$/ =~ v %>
<%= number_to_currency object.send(key.to_s).send(v.split("_cents")[0]) %>
<% else %>
<%= object.send(key.to_s).send(v) %>
<% end %>
|
<% end %>
<% else %>
<% value.each do |v| %>
<% if /_id$/ =~ v && Kernel.const_get(key.to_s.singularize.camelize).new.respond_to?(v.split('_id')[0]) %>
<%= Kernel.const_get(key.to_s.singularize.camelize).human_attribute_name(v.split('_id')[0]) %>
<% else %>
<%= Kernel.const_get(key.to_s.singularize.camelize).human_attribute_name(v) %>
<% end %>
|
<% end %>
<% object.send(key.to_s).each do |r| %>
<% value.each do |v| %>
<% if v.include?('.') %>
<% o = r %>
<% v.split('.').each{|m| o = o.send(m) if o } %>
<%= o %>
<% elsif r.send(v).class == Date or
r.send(v).class == DateTime or
r.send(v).class == ActiveSupport::TimeWithZone or
r.send(v).class == Time %>
<%=l r.send(v) %>
<% elsif r.send(v).respond_to? 'attached?' %>
<% if r.send(v).class == ActiveStorage::Attached::One %>
<% if r.send(v).attached? %>
<%= link_to rails_blob_path(r.send(v)), class: "btn btn-#{box_class} btn-xs", target: '_blank' do %>
Arquivo
<% end %>
<% end %>
<% end %>
<% elsif /_id$/ =~ v && r.respond_to?(v.split('_id')[0]) %>
<%= r.send(v.split("_id")[0])&.name %>
<% else %>
<%= r.send(v) %>
<% end %>
|
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>