class ProductsController < ApplicationController # GET /products # GET /products.json def index @products = User.all respond_to do |format| format.html # index.html.erb format.json { render json: @products } end end # GET /products/1 # GET /products/1.json def show @product = User.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @product } end end # GET /products/new # GET /products/new.json def new @product = User.new respond_to do |format| format.html # new.html.erb format.json { render json: @product } end end # GET /products/1/edit def edit @product = User.find(params[:id]) end # POST /products # POST /products.json def create @product = User.new(product_params) respond_to do |format| if @product.save format.html { redirect_to @product, notice: 'User was successfully created.' } format.json { render json: @product, status: :created, location: @product } else format.html { render action: "new" } format.json { render json: @product.errors, status: :unprocessable_entity } end end end # PUT /products/1 # PUT /products/1.json def update @product = User.find(params[:id]) respond_to do |format| if @product.update(product_params) format.html { redirect_to @product, notice: 'User was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @product.errors, status: :unprocessable_entity } end end end # DELETE /products/1 # DELETE /products/1.json def destroy @product = User.find(params[:id]) @product.destroy respond_to do |format| format.html { redirect_to products_url } format.json { head :no_content } end end private def product_params params.require(:product).permit(:product_title, :in_stock, :amount, :net_price, :units, :unit, :sku) end end