index.html.erb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <% name_attribute = attributes.find{ |a| a.name == "name" } %>
  2. <% has_name = !!name_attribute %>
  3. <div class="row">
  4. <div class="col-sm-6">
  5. <h1><%= plural_table_name.capitalize %></h1>
  6. </div>
  7. <div class="col-sm-6 text-right">
  8. <%%= link_to new_<%= singular_table_name %>_path, class: 'btn btn-primary' do %>
  9. Add New <%= human_name %>
  10. <%% end %>
  11. </div>
  12. </div>
  13. <div class="table-responsive">
  14. <table class="table table-striped table-bordered table-hover">
  15. <thead>
  16. <tr>
  17. <% if has_name %>
  18. <th>Name</th>
  19. <% end %>
  20. <% attributes.without(name_attribute).each do |attribute| -%>
  21. <th><%= attribute.human_name %></th>
  22. <% end -%>
  23. <% unless has_name %>
  24. <th></th>
  25. <% end %>
  26. </tr>
  27. </thead>
  28. <tbody>
  29. <%% @<%= plural_table_name%>.each do |<%= singular_table_name %>| %>
  30. <%%= content_tag :tr, id: dom_id(<%= singular_table_name %>), class: dom_class(<%= singular_table_name %>) do %>
  31. <% if has_name %>
  32. <td><%%= link_to <%= singular_table_name %>.name, <%= singular_table_name %> %></td>
  33. <% end %>
  34. <% attributes.without(name_attribute).each do |attribute| -%>
  35. <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
  36. <% end -%>
  37. <% unless has_name %>
  38. <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
  39. <% end %>
  40. <%% end %>
  41. <%% end %>
  42. </tbody>
  43. </table>
  44. </div>