Skip to content
Browse files

Update Create Resources Controller Class snippet to reflect JSON now …

…replaced XML as default
  • Loading branch information...
1 parent 683f6e6 commit 7105493989bc668ac9820f8641f1b4e02fae465a @joneslee85 joneslee85 committed
Showing with 16 additions and 18 deletions.
  1. +16 −18 Snippets/Create resources controller class.tmSnippet
View
34 Snippets/Create resources controller class.tmSnippet
@@ -7,33 +7,33 @@
before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy]
# GET /${1/./\l$0/}s
- # GET /${1/./\l$0/}s.xml
+ # GET /${1/./\l$0/}s.json
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 }
+ wants.json { render :json => @${1/./\l$0/}s }
end
end
# GET /${1/./\l$0/}s/1
- # GET /${1/./\l$0/}s/1.xml
+ # GET /${1/./\l$0/}s/1.json
def show
respond_to do |wants|
wants.html # show.html.erb
- wants.xml { render :xml => @${1/./\l$0/} }
+ wants.json { render :json => @${1/./\l$0/} }
end
end
# GET /${1/./\l$0/}s/new
- # GET /${1/./\l$0/}s/new.xml
+ # GET /${1/./\l$0/}s/new.json
def new
@${1/./\l$0/} = ${1:Model}.new
respond_to do |wants|
wants.html # new.html.erb
- wants.xml { render :xml => @${1/./\l$0/} }
+ wants.json { render :json => @${1/./\l$0/} }
end
end
@@ -42,45 +42,43 @@
end
# POST /${1/./\l$0/}s
- # POST /${1/./\l$0/}s.xml
+ # POST /${1/./\l$0/}s.json
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/} }
+ wants.html { redirect_to(@${1/./\l$0/}), :notice => '${1:Model} was successfully created.' }
+ wants.json { render :json => @${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 }
+ wants.json { render :json => @${1/./\l$0/}.errors, :status => :unprocessable_entity }
end
end
end
# PUT /${1/./\l$0/}s/1
- # PUT /${1/./\l$0/}s/1.xml
+ # PUT /${1/./\l$0/}s/1.json
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 }
+ wants.html { redirect_to(@${1/./\l$0/}), :notice => '${1:Model} was successfully updated.' }
+ wants.json { head :ok }
else
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
# DELETE /${1/./\l$0/}s/1
- # DELETE /${1/./\l$0/}s/1.xml
+ # DELETE /${1/./\l$0/}s/1.json
def destroy
@${1/./\l$0/}.destroy
respond_to do |wants|
wants.html { redirect_to(${1/./\l$0/}s_url) }
- wants.xml { head :ok }
+ wants.json { head :ok }
end
end

0 comments on commit 7105493

Please sign in to comment.
Something went wrong with that request. Please try again.