tap/app/controllers/products_controller.rb

42 lines
737 B
Ruby
Raw Normal View History

2014-11-10 14:52:54 +00:00
class ProductsController < ApplicationController
def new
@product = Product.new
end
def show
@product = Product.find(params[:id])
end
def create
@product = Product.new(product_params) # Not the final implementation!
if @product.save
redirect_to @product
else
render 'new'
end
end
def edit
2014-11-10 16:06:50 +00:00
@product = Product.find(params[:id])
2014-11-10 14:52:54 +00:00
end
2014-11-10 16:06:50 +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-10 14:52:54 +00:00
private
def product_params
params.require(:product).permit(:name, :sale_price, :purchase_price,
:image_path)
end
end