Skip to content

Added json to Create resources Controller #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions Snippets/Create resources controller class.tmSnippet
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,46 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>class ${1:Model}sController &lt; ApplicationController
<key>changed</key>
<dict>
<key>content</key>
<string>class ${1:Model}sController &lt; ApplicationController
before_filter :find_${1/./\l$0/}, :only =&gt; [: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 =&gt; @${1/./\l$0/}s }
wants.json { render :json =&gt; @${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 =&gt; @${1/./\l$0/} }
wants.json { render :json =&gt; @${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 =&gt; @${1/./\l$0/} }
wants.json { render :json =&gt; @${1/./\l$0/} }
end
end

Expand All @@ -43,6 +51,7 @@

# 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/}])

Expand All @@ -51,36 +60,42 @@
flash[:notice] = '${1:Model} was successfully created.'
wants.html { redirect_to(@${1/./\l$0/}) }
wants.xml { render :xml =&gt; @${1/./\l$0/}, :status =&gt; :created, :location =&gt; @${1/./\l$0/} }
wants.json { render :json =&gt; @${1/./\l$0/}, :status =&gt; :created, :location =&gt; @${1/./\l$0/} }
else
wants.html { render :action =&gt; "new" }
wants.xml { render :xml =&gt; @${1/./\l$0/}.errors, :status =&gt; :unprocessable_entity }
wants.json { render :json =&gt; @${1/./\l$0/}.errors, :status =&gt; :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.json { head :ok }
else
wants.html { render :action =&gt; "edit" }
wants.xml { render :xml =&gt; @${1/./\l$0/}.errors, :status =&gt; :unprocessable_entity }
end
wants.json { render :json =&gt; @${1/./\l$0/}.errors, :status =&gt; :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

Expand All @@ -91,12 +106,11 @@

end
</string>
<key>name</key>
<string>Create resources controller class</string>
<key>scope</key>
<string>source.ruby</string>
<key>tabTrigger</key>
<string>resources</string>
</dict>
<key>deleted</key>
<array/>
<key>isDelta</key>
<true/>
<key>uuid</key>
<string>F90BFB23-5706-484B-8108-B376A988C0A0</string>
</dict>
Expand Down