Commit 5c55234c

mo khan <mo@mokhan.ca>
2014-10-13 21:13:16
tidy up the detail page for a product search and use ajax to fetch search results.
1 parent 2d92ea7
app/views/admin/products/_index.html.erb
@@ -0,0 +1,12 @@
+<table class="table table-striped">
+  <tbody>
+  <% @products.each do |product| %>
+    <tr>
+      <td><%= link_to product.asin, admin_product_path(product.asin) %></td>
+      <td>
+        <%= link_to product.title, product.url %> is made by <%= product.manufacturer %> in category <%= product.category %>
+      </td>
+    </tr>
+  <% end %>
+  </tbody>
+</table>
app/views/admin/products/index.html.erb
@@ -4,30 +4,13 @@
   </div>
   <div class="span10">
     <h1>Product Catalog - Amazon</h1>
-    <%= form_tag admin_products_path, method: :get, name: 'search', class: 'form-horizontal' do %>
+    <%= form_tag admin_products_path(js: true), method: :get, name: 'search', class: 'form-horizontal', remote: true do %>
       <%= text_field_tag :q, params[:q], class: "search-query", placeholder: "Search" %>
       <%= submit_tag 'Search', class: 'btn btn-primary' %>
     <% end %>
-
-    <table class="table table-striped">
-      <tbody>
-      <% @products.each do |product| %>
-        <tr>
-          <td><%= link_to product.asin, admin_product_path(product.asin) %></td>
-          <td>
-            <%= link_to product.title, product.url %> is made by <%= product.manufacturer %> in category <%= product.category %>
-          </td>
-          <td>
-            <ul>
-              <% product.links.each do |link| %>
-                <li><%= link_to link.description, link.url %></li>
-              <% end %>
-            </ul>
-          </td>
-        </tr>
-      <% end %>
-      </tbody>
-    </table>
+    <div id="results-container">
+      <%= render partial: "index" %>
+    </div>
   </div>
 </div>
 
app/views/admin/products/index.js.erb
@@ -0,0 +1,1 @@
+$("#results-container").html('<%= escape_javascript(render partial: "index") %>');
app/views/admin/products/show.html.erb
@@ -9,19 +9,18 @@
       <td><%= link_to @product.asin, @product.detail_page_url %></td>
     </tr>
     <tr>
-      <td>attributes</td>
-      <td><%= @product.item_attributes %></td>
+      <td>images</td>
+      <td>
+        <%= image_tag(@product.large_image.url) %>
+        <%= image_tag(@product.medium_image.url) %>
+        <%= image_tag(@product.small_image.url) %>
+      </td>
     </tr>
     <tr>
-      <td>images</td>
+      <td>attributes</td>
       <td>
-        <% @product.image_sets.image_set.each do |image| %>
-          <%= image_tag image.large_image.url %>
-          <%= image_tag image.medium_image.url %>
-          <%= image_tag image.small_image.url %>
-          <%= image_tag image.swatch_image.url %>
-          <%= image_tag image.thumbnail_image.url %>
-          <%= image_tag image.tiny_image.url %>
+        <% @product.item_attributes.each do |(key, value)| %>
+          <p><%= key %>: <%= value %></p>
         <% end %>
       </td>
     </tr>