mdarby (owner)

Revisions

gist: 168837 Download_button fork
public
Public Clone URL: git://gist.github.com/168837.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class CrapsController < ApplicationController
  # GET /craps
  # GET /craps.xml
  def index
    @craps = Crap.all
 
    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @craps }
    end
  end
 
  # GET /craps/1
  # GET /craps/1.xml
  def show
    @crap = Crap.find(params[:id])
 
    respond_to do |format|
      format.html # show.html.erb
      format.xml { render :xml => @crap }
    end
  end
 
  # GET /craps/new
  # GET /craps/new.xml
  def new
    @crap = Crap.new
 
    respond_to do |format|
      format.html # new.html.erb
      format.xml { render :xml => @crap }
    end
  end
 
  # GET /craps/1/edit
  def edit
    @crap = Crap.find(params[:id])
  end
 
  # POST /craps
  # POST /craps.xml
  def create
    @crap = Crap.new(params[:crap])
 
    respond_to do |format|
      if @crap.save
        flash[:notice] = 'Crap was successfully created.'
        format.html { redirect_to(@crap) }
        format.xml { render :xml => @crap, :status => :created, :location => @crap }
      else
        format.html { render :action => "new" }
        format.xml { render :xml => @crap.errors, :status => :unprocessable_entity }
      end
    end
  end
 
  # PUT /craps/1
  # PUT /craps/1.xml
  def update
    @crap = Crap.find(params[:id])
 
    respond_to do |format|
      if @crap.update_attributes(params[:crap])
        flash[:notice] = 'Crap was successfully updated.'
        format.html { redirect_to(@crap) }
        format.xml { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml { render :xml => @crap.errors, :status => :unprocessable_entity }
      end
    end
  end
 
  # DELETE /craps/1
  # DELETE /craps/1.xml
  def destroy
    @crap = Crap.find(params[:id])
    @crap.destroy
 
    respond_to do |format|
      format.html { redirect_to(craps_url) }
      format.xml { head :ok }
    end
  end
end