tap/app/controllers/products_controller.rb
2014-11-25 13:41:22 +01:00

46 lines
771 B
Ruby

class ProductsController < ApplicationController
def new
@product = Product.new
end
def create
@product = Product.new(product_params)
if @product.save
redirect_to @product
else
render "new"
end
end
def show
@product = Product.find(params[:id])
end
def index
@products = Product.all
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to @product
else
render 'edit'
end
end
def delete
end
private
def product_params
params.require(:product).permit(:name, :purchase_price, :sale_price,
:img_path)
end
end