_form.html.erb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
  2. <%% if <%= singular_table_name %>.errors.any? %>
  3. <div id="error_explanation">
  4. <h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
  5. <ul>
  6. <%% <%= singular_table_name %>.errors.full_messages.each do |message| %>
  7. <li><%%= message %></li>
  8. <%% end %>
  9. </ul>
  10. </div>
  11. <%% end %>
  12. <% attributes.each do |attribute| -%>
  13. <div class="form-group">
  14. <% if attribute.password_digest? -%>
  15. <%%= form.label :password %>
  16. <%%= form.password_field :password, class: 'form-control' %>
  17. </div>
  18. <div class="form-group">
  19. <%%= form.label :password_confirmation %>
  20. <%%= form.password_field :password_confirmation, class: 'form-control' %>
  21. <% else -%>
  22. <%%= form.label :<%= attribute.column_name %> %>
  23. <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: 'form-control' %>
  24. <% end -%>
  25. </div>
  26. <% end -%>
  27. <div class="form-group">
  28. <%% if <%= model_resource_name %>.persisted? %>
  29. <div class="float-right">
  30. <%%= link_to 'Destroy', <%= model_resource_name %>, method: :delete, class: "text-danger", data: { confirm: 'Are you sure?' } %>
  31. </div>
  32. <%% end %>
  33. <%%= form.submit class: 'btn btn-primary' %>
  34. <%% if <%= model_resource_name %>.persisted? %>
  35. <%%= link_to "Cancel", <%= model_resource_name %>, class: "btn btn-link" %>
  36. <%% else %>
  37. <%%= link_to "Cancel", <%= index_helper %>_path, class: "btn btn-link" %>
  38. <%% end %>
  39. </div>
  40. <%% end %>