12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #---
- # Excerpted from "Agile Web Development with Rails",
- # published by The Pragmatic Bookshelf.
- # Copyrights apply to this code. It may not be used to create training material,
- # courses, books, articles, and the like. Contact us if you are in doubt.
- # We make no guarantees that this code is fit for any purpose.
- # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
- #---
- class CartsController < ApplicationController
- # GET /carts
- # GET /carts.json
- def index
- @carts = Cart.all
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @carts }
- end
- end
- # GET /carts/1
- # GET /carts/1.json
- def show
- @cart = Cart.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @cart }
- end
- end
- # GET /carts/new
- # GET /carts/new.json
- def new
- @cart = Cart.new
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @cart }
- end
- end
- # GET /carts/1/edit
- def edit
- @cart = Cart.find(params[:id])
- end
- # POST /carts
- # POST /carts.json
- def create
- @cart = Cart.new(params[:cart])
- respond_to do |format|
- if @cart.save
- format.html { redirect_to @cart, notice: 'Cart was successfully created.' }
- format.json { render json: @cart, status: :created, location: @cart }
- else
- format.html { render action: "new" }
- format.json { render json: @cart.errors, status: :unprocessable_entity }
- end
- end
- end
- # PUT /carts/1
- # PUT /carts/1.json
- def update
- @cart = Cart.find(params[:id])
- respond_to do |format|
- if @cart.update_attributes(params[:cart])
- format.html { redirect_to @cart, notice: 'Cart was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @cart.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /carts/1
- # DELETE /carts/1.json
- def destroy
- @cart = Cart.find(params[:id])
- @cart.destroy
- respond_to do |format|
- format.html { redirect_to carts_url }
- format.json { head :no_content }
- end
- end
- end
|