Created
November 2, 2012 13:23
-
-
Save adamdilek/4001352 to your computer and use it in GitHub Desktop.
Product Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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