index.html.erb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <%= turbo_stream_from "products" %>
  2. <%= turbo_refreshes_with method: :morph, scroll: :preserve %>
  3. <div class="w-full">
  4. <% if notice.present? %>
  5. <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium
  6. rounded-lg inline-block" id="notice">
  7. <%= notice %>
  8. </p>
  9. <% end %>
  10. <div class="flex justify-between items-center pb-8">
  11. <h1 class="mx-auto font-bold text-4xl">Products</h1>
  12. </div>
  13. <table id="products" class="mx-auto">
  14. <tfoot>
  15. <tr>
  16. <td colspan="3">
  17. <div class="mt-8">
  18. <%= link_to 'New product',
  19. new_product_path,
  20. class: "inline rounded-lg py-3 px-5 bg-green-600
  21. text-white block font-medium" %>
  22. </div>
  23. </td>
  24. </tr>
  25. </tfoot>
  26. <tbody>
  27. <% @products.each do |product| %>
  28. <tr class="<%= cycle('bg-green-50', 'bg-white') %>">
  29. <td class="px-2 py-3">
  30. <%= image_tag(product.image, class: 'w-40') %>
  31. </td>
  32. <td>
  33. <h1 class="text-xl font-bold"><%= product.title %></h1>
  34. <p class="my-3">
  35. <%= truncate(strip_tags(product.description),
  36. length: 80) %>
  37. </p>
  38. <p>
  39. <%= number_to_currency(product.price) %>
  40. </p>
  41. </td>
  42. <td class="px-3">
  43. <ul>
  44. <li>
  45. <%= link_to 'Show',
  46. product,
  47. class: 'hover:underline' %>
  48. </li>
  49. <li>
  50. <%= link_to 'Edit',
  51. edit_product_path(product),
  52. class: 'hover:underline' %>
  53. </li>
  54. <li>
  55. <%= button_to 'Destroy',
  56. product,
  57. method: :delete,
  58. class: 'hover:underline',
  59. data: { turbo_confirm: "Are you sure?" } %>
  60. </li>
  61. </ul>
  62. </td>
  63. </tr>
  64. <% end %>
  65. </tbody>
  66. </table>
  67. </div>