This project is archived and is in readonly mode.
[PATCH] Make redirect_to support blocks.
Reported by Nando Vieira | September 16th, 2010 @ 09:59 PM | in 3.1
With the new respond_with
method, you can't provide
the :location
option that relies on an invalid object
(that will raise a router error).
class UsersController < ApplicationController
def create
@user = User.create(params[:user])
respond_with @user, :location => edit_user_path(@user)
end
def edit
@user = User.find(params[:id])
respond_with @user
end
end
A solution for this is passing a block that can be executed later on.
class UsersController < ApplicationController
def create
@user = User.create(params[:user])
respond_with @user, :location => proc { edit_user_path(@user) }
end
def edit
@user = User.find(params[:id])
respond_with @user
end
end
I'm attaching a patch that fixes this issue.
Comments and changes to this ticket
-
Nando Vieira September 16th, 2010 @ 10:02 PM
- Title changed from Make return_to support blocks. to [PATCH] Make return_to support blocks.
- Tag changed from block, redirection, redirect_to to actioncontroller, block, patch, redirection, redirect_to
-
Nando Vieira September 16th, 2010 @ 11:19 PM
- Title changed from [PATCH] Make return_to support blocks. to [PATCH] Make redirect_to support blocks.
-
Nando Vieira September 16th, 2010 @ 11:20 PM
- no changes were found...
-
Rohit Arondekar September 17th, 2010 @ 01:45 AM
- State changed from new to open
- Importance changed from to Low
Opening ticket to get more eyes on this.
-
José Valim September 18th, 2010 @ 07:27 PM
- Milestone set to 3.1
Do we really need to use instance_eval?
And Nando, could you please generate the patch using git format-patch? This way it will keep you as the author. -
Nando Vieira September 19th, 2010 @ 12:52 AM
Hey Rockstar! I thought of yielding the controller instance, but we often have private methods and instance variables, so
instance_eval
makes more sense, I think.The new patch is attached.
-
Repository September 24th, 2010 @ 12:11 PM
- State changed from open to resolved
(from [7223fe7faf26f717aee056942aadecc62e8f5cd9]) Make redirect_to accept blocks [#5643 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/7223fe7faf26f717aee056942aadec...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5643 [PATCH] Make redirect_to support blocks. (from [7223fe7faf26f717aee056942aadecc62e8f5cd9]) Make re...