invoice_keeper/app/controllers/products_controller.rb

46 lines
870 B
Ruby

class ProductsController < ApplicationController
def index
@products = Product.where(user_id: current_user.id).order('name ASC')
end
def new
@product = Product.new
end
def create
@product = Product.new(product_params)
@product.user_id = current_user.id
if @product.save
redirect_to products_path
else
render :new
end
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to products_path
else
render :edit
end
end
def destroy
@product = Product.find(params[:id])
@product.destroy unless @product.blank?
redirect_to products_path
end
private
def product_params
params.require(:product).permit(:name, :vat_id, :netto_price, :qnt_name)
end
end