tap/app/controllers/products_controller.rb

44 lines
816 B
Ruby
Raw Normal View History

2014-11-24 21:45:32 +01:00
class ProductsController < ApplicationController
2014-12-17 07:31:51 +01:00
load_and_authorize_resource
2015-03-28 14:36:07 +01:00
respond_to :html, :js
2014-11-24 21:45:32 +01:00
def new
end
def create
if @product.save
flash[:success] = "Product created!"
redirect_to products_path
2014-11-24 21:45:32 +01:00
else
render 'new'
2014-11-24 21:45:32 +01:00
end
end
2014-11-25 13:09:55 +01:00
def index
@products = Product.all
2014-12-10 22:06:36 +01:00
@categories = Product.categories
render 'products_list/listview' if current_user.admin?
2014-11-25 13:09:55 +01:00
end
2014-11-24 21:45:32 +01:00
def edit
2015-04-03 23:56:13 +02:00
respond_with @product
2014-11-24 21:45:32 +01:00
end
2014-11-25 13:41:22 +01:00
def update
2015-03-28 14:36:07 +01:00
@product.update_attributes product_params
respond_with @product
2014-11-25 13:41:22 +01:00
end
2015-09-20 21:21:18 +02:00
def from_barcode
2015-09-23 11:09:24 +02:00
render json: Barcode.find_by_code(params.require(:barcode)).try(:product)
2015-09-20 21:21:18 +02:00
end
2014-11-24 21:45:32 +01:00
private
2014-11-25 13:41:22 +01:00
def product_params
2015-09-20 21:21:18 +02:00
params.require(:product).permit(:name, :price, :avatar, :category, :stock, :calories, :deleted, :barcode)
2014-11-24 21:45:32 +01:00
end
end