Skip to content

Instantly share code, notes, and snippets.

@adamdilek
Created November 2, 2012 13:23
Show Gist options
  • Select an option

  • Save adamdilek/4001352 to your computer and use it in GitHub Desktop.

Select an option

Save adamdilek/4001352 to your computer and use it in GitHub Desktop.
Product Controller
class ProductsController < ApplicationController
before_filter :authenticate_user!
# GET /products
# GET /products.json
def index
@products = Product.all
render json: @products
end
# GET /products/1
# GET /products/1.json
def show
@product = Product.find(params[:id])
render json: @product
end
# GET /products/new
# GET /products/new.json
def new
@product = Product.new
render json: @product
end
# POST /products
# POST /products.json
def create
@product = Product.new(params[:product])
if @product.save
render json: @product, status: :created, location: @product
else
render json: @product.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
@product = Product.find(params[:id])
if @product.update_attributes(params[:product])
head :no_content
else
render json: @product.errors, status: :unprocessable_entity
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product = Product.find(params[:id])
@product.destroy
head :no_content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment