Created
June 5, 2013 20:43
-
-
Save kylemacey/5717162 to your computer and use it in GitHub Desktop.
Handy snippet for responding in your `create` methods
This file contains hidden or 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
| <snippet> | |
| <content><![CDATA[ | |
| respond_to do |format| | |
| if @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}.save! | |
| format.html { redirect_to @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}, notice: "${2:${TM_FILENAME/(.*?)(s?)(_controller\..+)/\u$1/}} has been saved successfully" } | |
| format.json { render json: @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}} } | |
| else | |
| format.html { render action: "new" } | |
| format.json { render json: @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| ]]></content> | |
| <tabTrigger>save</tabTrigger> | |
| <description>Save and Respond</description> | |
| <scope>source.ruby.rails</scope> | |
| </snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment