<% 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 %>

<%= object.class.model_name.human %>

<% unless hide_links %> <% if show_actions.include?('new') && can?(:new, object.class) %> <% if nested_resource %> <%= link_to eval_with_rescue("new_#{parent_resource.class.model_name.singular}_#{object.class.model_name.singular}_path(#{parent_resource.id})"), class: "btn btn-#{box_class} btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Cadastrar' } do %> Cadastrar <% end %> <% else %> <%= link_to eval("new_#{object.class.model_name.singular}_path"), class: "btn btn-#{box_class} btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Cadastrar' } do %> Cadastrar <% end %> <% end %> <% end %> <% if show_actions.include?('edit') && can?(:edit, object) %> <%= link_to eval_with_rescue("edit_#{object.class.model_name.singular}_path(#{object.id})"), class: "btn btn-warning btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %> Editar <% end %> <% end %> <% if show_actions.include?('index') %> <% if nested_resource %> <%= link_to 'Listagem', eval_with_rescue("#{parent_resource.class.model_name.singular}_#{object.class.model_name.plural}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %> <% else %> <%= link_to 'Listagem', eval_with_rescue("#{object.class.model_name.plural}_path"), class: "btn btn-default btn-xs" %> <% end %> <% end %> <% end %> <% if block_given? %> <%= yield %> <% end %>
<% end %>
<% unless hide_table_header %> <% end %> <% show_columns.each do |column| %> <% unless /_currency$/ =~ column %> <% end %> <% end %>
<%= t('field') %> <%= t('value') %>
<% 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 %>
<% 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) %>

<%= Kernel.const_get(key.to_s.singularize.camelize).model_name.human %>

<% unless hide_table_header %> <% end %> <% value.each do |v| %> <% end %>
<%= t('field') %> <%= t('value') %>
<% 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 %>
<% else %>

<%= Kernel.const_get(key.to_s.singularize.camelize).model_name.human.pluralize %>

<% value.each do |v| %> <% end %> <% object.send(key.to_s).each do |r| %> <% value.each do |v| %> <% end %> <% end %>
<% 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 %>
<% 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 %>