# class ProductsController

### Public Instance Methods

create() click to toggle source

POST /products POST /products.json

    # File app/controllers/products_controller.rb, line 26
    def create
      @product = Product.new(product_params)

      respond_to do |format|
        if @product.save
          format.html { redirect_to @product,
            notice: 'Product was successfully created.' }
          format.json { render action: 'show', status: :created,
            location: @product }
        else
          format.html { render action: 'new' }
          format.json { render json: @product.errors,
            status: :unprocessable_entity }
        end
      end
    end

destroy() click to toggle source

DELETE /products/1 DELETE /products/1.json

    # File app/controllers/products_controller.rb, line 61
    def destroy
      @product.destroy
      respond_to do |format|
        format.html { redirect_to products_url }
        format.json { head :no_content }
      end
    end

edit() click to toggle source

GET /products/1/edit

    # File app/controllers/products_controller.rb, line 21
    def edit
    end

index() click to toggle source

GET /products GET /products.json

    # File app/controllers/products_controller.rb, line 6
    def index
      @products = Product.all
    end

new() click to toggle source

GET /products/new

    # File app/controllers/products_controller.rb, line 16
    def new
      @product = Product.new
    end

show() click to toggle source

GET /products/1 GET /products/1.json

    # File app/controllers/products_controller.rb, line 12
    def show
    end

update() click to toggle source

PATCH/PUT /products/1 PATCH/PUT /products/1.json

    # File app/controllers/products_controller.rb, line 45
    def update
      respond_to do |format|
        if @product.update(product_params)
          format.html { redirect_to @product,
            notice: 'Product 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

who_bought() click to toggle source

START:#who_bought

    # File app/controllers/products_controller.rb, line 70
      def who_bought
        @product = Product.find(params[:id])
        @latest_order = @product.orders.order(:updated_at).last
        if stale?(@latest_order)
          respond_to do |format|
            format.html
            format.xml
            format.atom
            format.json { render json: @product.to_json(include: :orders) }
          end
        end
      end