tap/app/controllers/products_controller.rb

49 lines
838 B
Ruby
Raw Normal View History

2014-11-24 20:45:32 +00:00
class ProductsController < ApplicationController
def new
@product = Product.new
end
def create
2014-11-25 12:41:22 +00:00
@product = Product.new(product_params)
2014-11-24 20:45:32 +00:00
if @product.save
redirect_to @product
else
render 'new'
2014-11-24 20:45:32 +00:00
end
end
def show
@product = Product.find(params[:id])
end
2014-11-25 12:09:55 +00:00
def index
@products = Product.all
end
2014-11-24 20:45:32 +00:00
def edit
2014-11-25 12:09:55 +00:00
@product = Product.find(params[:id])
2014-11-24 20:45:32 +00:00
end
2014-11-25 12:41:22 +00:00
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to @product
else
render 'edit'
end
end
2014-11-26 10:58:51 +00:00
def destroy
Product.find(params[:id]).destroy
redirect_to products_path
2014-11-24 20:45:32 +00:00
end
private
2014-11-25 12:41:22 +00:00
def product_params
2014-11-24 20:45:32 +00:00
params.require(:product).permit(:name, :purchase_price, :sale_price,
:avatar)
2014-11-24 20:45:32 +00:00
end
end