<% modelo = f.object.class.reflect_on_association(key.to_s).class_name.constantize %> <% if f.object.present? && !f.object.send(key).present? %> <% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %> <% f.object.send(key).build %> <% else %> <% f.object.send("build_#{key}") %> <% end %> <% end %> <%= f.simple_fields_for key do |g| %>

<%= groups[:label] %>

<% groups[:fields].each do |field| %> <% if field[:sf].present? && field[:sf][:grupo].present? %> <%= render "/crud/form_group", f: g, key: field[:attribute], groups: field[:sf] %> <% else %> <% if modelo.reflect_on_association(field[:attribute]).class == ActiveRecord::Reflection::BelongsToReflection && is_raro_crud(modelo.reflect_on_association(field[:attribute]).class_name) && field[:sf][:add_registro].nil?%> <%= render_plus_button(field,g,modelo,f.object) %> <%else%> <%= render_field(field,g,modelo,f.object) %> <%end%> <% end %> <% end %> <% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
<%= g.link_to_remove "Remover #{groups[:sublabel] || groups[:label].downcase}" %>
<% end %> <% end %> <% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
<%= f.link_to_add "Adicionar #{groups[:sublabel] || groups[:label].downcase}", key %>
<% end %>