Created
April 21, 2010 19:29
-
-
Save rscarvalho/374297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ${1:Model}sController < ApplicationController | |
before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy] | |
# GET /${1/./\l$0/}s | |
# GET /${1/./\l$0/}s.xml | |
def index | |
@${1/./\l$0/}s = ${1:Model}.all | |
respond_to do |wants| | |
wants.html # index.html.erb | |
wants.xml { render :xml => @${1/./\l$0/}s } | |
end | |
end | |
# GET /${1/./\l$0/}s/1 | |
# GET /${1/./\l$0/}s/1.xml | |
def show | |
respond_to do |wants| | |
wants.html # show.html.erb | |
wants.xml { render :xml => @${1/./\l$0/} } | |
end | |
end | |
# GET /${1/./\l$0/}s/new | |
# GET /${1/./\l$0/}s/new.xml | |
def new | |
@${1/./\l$0/} = ${1:Model}.new | |
respond_to do |wants| | |
wants.html # new.html.erb | |
wants.xml { render :xml => @${1/./\l$0/} } | |
end | |
end | |
# GET /${1/./\l$0/}s/1/edit | |
def edit | |
end | |
# POST /${1/./\l$0/}s | |
# POST /${1/./\l$0/}s.xml | |
def create | |
@${1/./\l$0/} = ${1:Model}.new(params[:${1/./\l$0/}]) | |
respond_to do |wants| | |
if @${1/./\l$0/}.save | |
flash[:notice] = '${1:Model} was successfully created.' | |
wants.html { redirect_to(@${1/./\l$0/}) } | |
wants.xml { render :xml => @${1/./\l$0/}, :status => :created, :location => @${1/./\l$0/} } | |
else | |
wants.html { render :action => "new" } | |
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /${1/./\l$0/}s/1 | |
# PUT /${1/./\l$0/}s/1.xml | |
def update | |
respond_to do |wants| | |
if @${1/./\l$0/}.update_attributes(params[:${1/./\l$0/}]) | |
flash[:notice] = '${1:Model} was successfully updated.' | |
wants.html { redirect_to(@${1/./\l$0/}) } | |
wants.xml { head :ok } | |
else | |
wants.html { render :action => "edit" } | |
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /${1/./\l$0/}s/1 | |
# DELETE /${1/./\l$0/}s/1.xml | |
def destroy | |
@${1/./\l$0/}.destroy | |
respond_to do |wants| | |
wants.html { redirect_to(${1/./\l$0/}s_url) } | |
wants.xml { head :ok } | |
end | |
end | |
private | |
def find_${1/./\l$0/} | |
@${1/./\l$0/} = ${1:Model}.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment