change index of products in table view

This commit is contained in:
benji 2015-03-28 14:36:07 +01:00
parent 044ad2051d
commit 0bcbc20702
6 changed files with 38 additions and 7 deletions

View file

@ -22,3 +22,6 @@
margin-bottom: 20px;
}
#products-table .form-group {
margin-bottom: 0;
}

View file

@ -1,6 +1,8 @@
class ProductsController < ApplicationController
load_and_authorize_resource
respond_to :html, :js
def new
@product = Product.new
end
@ -17,6 +19,9 @@ class ProductsController < ApplicationController
def index
@products = Product.all
@categories = Product.categories
if current_user.admin?
render 'products_list/listview'
end
end
def edit
@ -25,12 +30,8 @@ class ProductsController < ApplicationController
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
flash[:success] = "Succesfully updated product"
redirect_to products_path
else
render 'edit'
end
@product.update_attributes product_params
respond_with @product
end
def destroy

View file

@ -17,7 +17,7 @@
class Product < ActiveRecord::Base
has_many :order_items
has_attached_file :avatar, styles: { dagschotel: "80x80>", medium: "100x100>" }, default_style: :medium
has_attached_file :avatar, styles: { dagschotel: "80x80>", medium: "100x100>", small: "40x40>" }, default_style: :medium
enum category: %w(food beverages other)

View file

@ -0,0 +1 @@
$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>");

View file

@ -0,0 +1,9 @@
<tr id="products_row_<%= dom_id(product) %>">
<%= f_form_for product, remote: true do |f| %>
<td><%= image_tag product.avatar(:small) %></td>
<td><%= f.text_field :name, skip_label: true %></td>
<td><%= f.price_field :price, skip_label: true %></td>
<td><%= f.number_field :stock, skip_label: true %></td>
<td><%= f.submit "Save" %></td>
<% end %>
</tr>

View file

@ -0,0 +1,17 @@
<div class="row products">
<div class="col-md-8 col-md-offset-2">
<h1>Products</h1>
<%= render partial: 'flash' %>
<table id="products-table" class="table table-striped">
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
<th></th>
</tr>
<%= render partial: 'products_list/product_row', collection: @products, as: :product %>
</table>
</div>
</div>