change index of products in table view
This commit is contained in:
parent
044ad2051d
commit
0bcbc20702
6 changed files with 38 additions and 7 deletions
|
@ -22,3 +22,6 @@
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#products-table .form-group {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
class ProductsController < ApplicationController
|
class ProductsController < ApplicationController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
respond_to :html, :js
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@product = Product.new
|
@product = Product.new
|
||||||
end
|
end
|
||||||
|
@ -17,6 +19,9 @@ class ProductsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@products = Product.all
|
@products = Product.all
|
||||||
@categories = Product.categories
|
@categories = Product.categories
|
||||||
|
if current_user.admin?
|
||||||
|
render 'products_list/listview'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@ -25,12 +30,8 @@ class ProductsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@product = Product.find(params[:id])
|
@product = Product.find(params[:id])
|
||||||
if @product.update_attributes(product_params)
|
@product.update_attributes product_params
|
||||||
flash[:success] = "Succesfully updated product"
|
respond_with @product
|
||||||
redirect_to products_path
|
|
||||||
else
|
|
||||||
render 'edit'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
has_many :order_items
|
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)
|
enum category: %w(food beverages other)
|
||||||
|
|
||||||
|
|
1
app/views/products/update.js.erb
Normal file
1
app/views/products/update.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>");
|
9
app/views/products_list/_product_row.html.erb
Normal file
9
app/views/products_list/_product_row.html.erb
Normal 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>
|
17
app/views/products_list/listview.html.erb
Normal file
17
app/views/products_list/listview.html.erb
Normal 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>
|
Loading…
Reference in a new issue