<% excluded_columns ||= [] %> <% restricted_columns ||= {} %> <% nested_resource ||= false %> <% parent_resource ||= false %> <% back_link ||= false %> <% box_class ||= 'primary' %> <% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %> <% form_ordered_fields ||= (form_fields.nil? ? object.class.column_names : form_fields.keys) %> <%= simple_form_for(nested_resource ? [parent_resource, object] : object) do |f| %>

Dados do <%=t object.class.model_name.human %> <% if parent_resource %> <%= link_to 'Cancelar', eval_with_rescue("#{parent_resource.class.model_name.to_s.downcase}_#{controller_name}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %> <% else %> <%= link_to 'Cancelar', eval_with_rescue("#{controller_name}_path"), class: "btn btn-default btn-xs" %> <% end %> <%= f.submit 'Salvar', class: "btn btn-#{box_class} btn-xs" %>

<% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns).each do |column| %> <% wphtml = "col-md-#{(form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:size] : form_fields[column.to_sym] ) || 12}" %> <% hint = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:hint] : '') %> <% placeholder = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:placeholder] : '') %> <% if object.class.column_for_attribute(column).type == :text %> <%= f.input column, input_html: { rows: 10, cols: 20 }, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %> <% elsif [:date, :datetime].include?(object.class.column_for_attribute(column).type) %> <%= f.input column, html5: true, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %> <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %> <% if restricted_columns.keys.include?(column.to_sym) %> <%= f.association column.split("_id")[0], label: restricted_columns[column.to_sym][:label], collection: restricted_columns[column.to_sym][:collection], wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %> <% else %> <%= f.association column.split("_id")[0], wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %> <% end %> <% else %> <%= f.input column, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %> <% end %> <% end %>
<% end %>