Skip to content

Instantly share code, notes, and snippets.

@psousa
Created June 27, 2009 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save psousa/136980 to your computer and use it in GitHub Desktop.
Save psousa/136980 to your computer and use it in GitHub Desktop.
snippet for resftull controllers in rails. Scope selector: source.ruby.rails
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment