Created
December 28, 2009 11:43
-
-
Save josevalim/264639 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
## Problem: change where to redirect on save with success | |
# scaffold respond_with | |
def create | |
@post = Post.new(params[:post]) | |
flash[:notice] = "Post was successfully created" if @post.save | |
respond_with(@post) | |
end | |
# changed respond_with | |
def create | |
@post = Post.new(params[:post]) | |
respond_with(@post) do |format| | |
if @post.save | |
flash[:notice] = "Post was successfully created" | |
format.html { redirect_to another_url } | |
end | |
end | |
end | |
# proposal: respond_with success/failure blocks | |
def create | |
@post = Post.new(params[:post]) | |
flash[:notice] = "Post was successfully created" if @post.save | |
respond_with(@post) do |success, failure| | |
success.html { redirect_to another_url } | |
# Easy to overwrite failure as well | |
# failure.html { redirect_to just_another_one_url } | |
end | |
end | |
# scaffold respond_to | |
def create | |
@post = Post.new(params[:post]) | |
respond_to do |format| | |
if @post.save | |
flash[:notice] = "Post was successfully created" | |
format.html { redirect_to post_url } | |
else | |
format.html { render :new } | |
end | |
end | |
end | |
# changed respond_to | |
def create | |
@post = Post.new(params[:post]) | |
respond_to do |format| | |
if @post.save | |
flash[:notice] = "Post was successfully created" | |
format.html { redirect_to another_url } | |
else | |
format.html { render :new } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment