psousa (owner)

Forks

Revisions

gist: 136980 Download_button fork
public
Description:
snippet for resftull controllers in rails. Scope selector: source.ruby.rails
Public Clone URL: git://gist.github.com/136980.git
Embed All Files: show embed
restfull controller textmate snippet #
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
def index
  @${1:things} = ${2:Thing}.find :all
 
  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @$1 }
  end
end
 
def show
  @${3:thing} = $2.find(params[:id])
 
  respond_to do |format|
    format.html # show.html.erb
    format.xml { render :xml => @$3 }
  end
end
 
def new
  @$3 = $2.new
 
  respond_to do |format|
    format.html # new.html.erb
    format.xml { render :xml => @$3 }
  end
end
 
def edit
  @$3 = $2.find(params[:id])
end
 
def create
  @$3 = $2.new(params[:$3])
 
  respond_to do |format|
    if @$3.save
      flash[:notice] = '$2 was successfully created.'
      format.html { redirect_to(@$3) }
      format.xml { render :xml => @$3, :status => :created, :location => @$3 }
    else
      format.html { render :action => "new" }
      format.xml { render :xml => @$3.errors, :status => :unprocessable_entity }
    end
  end
end
 
def update
  @$3 = $2.find(params[:id])
 
  respond_to do |format|
    if @$3.update_attributes(params[:$3])
      flash[:notice] = '$2 was successfully updated.'
      format.html { redirect_to(@$3) }
      format.xml { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml { render :xml => @$3.errors, :status => :unprocessable_entity }
    end
  end
end
 
def destroy
  @$3 = $2.find(params[:id])
  @$3.destroy
 
  respond_to do |format|
    format.html { redirect_to(admin_$1_url) }
    format.xml { head :ok }
  end
end