Skip to content

Commit

Permalink
Update Create Resources Controller Class snippet to reflect JSON now …
Browse files Browse the repository at this point in the history
…replaced XML as default
  • Loading branch information
Trung Lê committed Oct 1, 2011
1 parent 683f6e6 commit 7105493
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions Snippets/Create resources controller class.tmSnippet
Expand Up @@ -7,33 +7,33 @@
before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy] before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy]
# GET /${1/./\l$0/}s # GET /${1/./\l$0/}s
# GET /${1/./\l$0/}s.xml # GET /${1/./\l$0/}s.json
def index def index
@${1/./\l$0/}s = ${1:Model}.all @${1/./\l$0/}s = ${1:Model}.all
respond_to do |wants| respond_to do |wants|
wants.html # index.html.erb wants.html # index.html.erb
wants.xml { render :xml => @${1/./\l$0/}s } wants.json { render :json => @${1/./\l$0/}s }
end end
end end
# GET /${1/./\l$0/}s/1 # GET /${1/./\l$0/}s/1
# GET /${1/./\l$0/}s/1.xml # GET /${1/./\l$0/}s/1.json
def show def show
respond_to do |wants| respond_to do |wants|
wants.html # show.html.erb wants.html # show.html.erb
wants.xml { render :xml => @${1/./\l$0/} } wants.json { render :json => @${1/./\l$0/} }
end end
end end
# GET /${1/./\l$0/}s/new # GET /${1/./\l$0/}s/new
# GET /${1/./\l$0/}s/new.xml # GET /${1/./\l$0/}s/new.json
def new def new
@${1/./\l$0/} = ${1:Model}.new @${1/./\l$0/} = ${1:Model}.new
respond_to do |wants| respond_to do |wants|
wants.html # new.html.erb wants.html # new.html.erb
wants.xml { render :xml => @${1/./\l$0/} } wants.json { render :json => @${1/./\l$0/} }
end end
end end
Expand All @@ -42,45 +42,43 @@
end end
# POST /${1/./\l$0/}s # POST /${1/./\l$0/}s
# POST /${1/./\l$0/}s.xml # POST /${1/./\l$0/}s.json
def create def create
@${1/./\l$0/} = ${1:Model}.new(params[:${1/./\l$0/}]) @${1/./\l$0/} = ${1:Model}.new(params[:${1/./\l$0/}])
respond_to do |wants| respond_to do |wants|
if @${1/./\l$0/}.save if @${1/./\l$0/}.save
flash[:notice] = '${1:Model} was successfully created.' wants.html { redirect_to(@${1/./\l$0/}), :notice => '${1:Model} was successfully created.' }
wants.html { redirect_to(@${1/./\l$0/}) } wants.json { render :json => @${1/./\l$0/}, :status => :created, :location => @${1/./\l$0/} }
wants.xml { render :xml => @${1/./\l$0/}, :status => :created, :location => @${1/./\l$0/} }
else else
wants.html { render :action => "new" } wants.html { render :action => "new" }
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } wants.json { render :json => @${1/./\l$0/}.errors, :status => :unprocessable_entity }
end end
end end
end end
# PUT /${1/./\l$0/}s/1 # PUT /${1/./\l$0/}s/1
# PUT /${1/./\l$0/}s/1.xml # PUT /${1/./\l$0/}s/1.json
def update def update
respond_to do |wants| respond_to do |wants|
if @${1/./\l$0/}.update_attributes(params[:${1/./\l$0/}]) if @${1/./\l$0/}.update_attributes(params[:${1/./\l$0/}])
flash[:notice] = '${1:Model} was successfully updated.' wants.html { redirect_to(@${1/./\l$0/}), :notice => '${1:Model} was successfully updated.' }
wants.html { redirect_to(@${1/./\l$0/}) } wants.json { head :ok }
wants.xml { head :ok }
else else
wants.html { render :action => "edit" } wants.html { render :action => "edit" }
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity } wants.json { render :json => @${1/./\l$0/}.errors, :status => :unprocessable_entity }
end end
end end
end end
# DELETE /${1/./\l$0/}s/1 # DELETE /${1/./\l$0/}s/1
# DELETE /${1/./\l$0/}s/1.xml # DELETE /${1/./\l$0/}s/1.json
def destroy def destroy
@${1/./\l$0/}.destroy @${1/./\l$0/}.destroy
respond_to do |wants| respond_to do |wants|
wants.html { redirect_to(${1/./\l$0/}s_url) } wants.html { redirect_to(${1/./\l$0/}s_url) }
wants.xml { head :ok } wants.json { head :ok }
end end
end end
Expand Down

0 comments on commit 7105493

Please sign in to comment.