diff --git a/app/assets/stylesheets/products.css.scss b/app/assets/stylesheets/products.css.scss
index 55739c9..2a9487c 100644
--- a/app/assets/stylesheets/products.css.scss
+++ b/app/assets/stylesheets/products.css.scss
@@ -25,3 +25,10 @@
#products-table .form-group {
margin-bottom: 0;
}
+
+#products-table tr {
+ height: 57px;
+ td {
+ vertical-align: middle;
+ }
+}
diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb
index 2af86f8..d44d99d 100644
--- a/app/controllers/products_controller.rb
+++ b/app/controllers/products_controller.rb
@@ -26,6 +26,7 @@ class ProductsController < ApplicationController
def edit
@product = Product.find(params[:id])
+ respond_with @product
end
def update
diff --git a/app/views/application/_errors.html.erb b/app/views/application/_errors.html.erb
new file mode 100644
index 0000000..a0b3ddf
--- /dev/null
+++ b/app/views/application/_errors.html.erb
@@ -0,0 +1,14 @@
+<% if object.errors.any? %>
+
+<% end %>
diff --git a/app/views/products/edit.js.erb b/app/views/products/edit.js.erb
new file mode 100644
index 0000000..c230148
--- /dev/null
+++ b/app/views/products/edit.js.erb
@@ -0,0 +1 @@
+$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render "products_list/product_edit_row", product: @product %>")
diff --git a/app/views/products/update.js.erb b/app/views/products/update.js.erb
index b0694e6..384a31c 100644
--- a/app/views/products/update.js.erb
+++ b/app/views/products/update.js.erb
@@ -1 +1,6 @@
-$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>");
+<% if @product.errors.any? %>
+ $('#products-errors').html("<%= j render 'errors', object: @product %>")
+<% else %>
+ $('#products-errors').html('')
+ $("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>");
+<% end %>
diff --git a/app/views/products_list/_product_edit_row.html.erb b/app/views/products_list/_product_edit_row.html.erb
new file mode 100644
index 0000000..9ef9b8f
--- /dev/null
+++ b/app/views/products_list/_product_edit_row.html.erb
@@ -0,0 +1,20 @@
+
+ <%= f_form_for product, remote: true do |f| %>
+ <%= image_tag product.avatar(:small) %> |
+ <%= f.text_field :name, skip_label: true %> |
+ <%= f.price_field :price, skip_label: true %> |
+ <%= f.number_field :stock, skip_label: true %> |
+ <%= f.button "Update", class: "btn btn-primary" %> |
+ <%= javascript_tag do %>
+ var id = "#edit_<%= dom_id(product) %>";
+ var inputs = $(id).parent().find('input');
+
+ $(id).parent().find('button').on('click', function(e) {
+ e.preventDefault();
+ $(id).append(inputs.clone());
+ $(id).append('');
+ $(id).submit();
+ });
+ <% end %>
+ <% end %>
+
diff --git a/app/views/products_list/_product_row.html.erb b/app/views/products_list/_product_row.html.erb
index e0da8c3..f2fc527 100644
--- a/app/views/products_list/_product_row.html.erb
+++ b/app/views/products_list/_product_row.html.erb
@@ -1,9 +1,7 @@
- <%= f_form_for product, remote: true do |f| %>
- <%= image_tag product.avatar(:small) %> |
- <%= f.text_field :name, skip_label: true %> |
- <%= f.price_field :price, skip_label: true %> |
- <%= f.number_field :stock, skip_label: true %> |
- <%= f.submit "Save" %> |
- <% end %>
+ <%= image_tag product.avatar(:small) %> |
+ <%= product.name %> |
+ <%= euro(product.price) %> |
+ <%= product.stock %> |
+ <%= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true %> |
diff --git a/app/views/products_list/listview.html.erb b/app/views/products_list/listview.html.erb
index 47cf371..85091dd 100644
--- a/app/views/products_list/listview.html.erb
+++ b/app/views/products_list/listview.html.erb
@@ -1,3 +1,4 @@
+