This project is archived and is in readonly mode.

#5643 ✓resolved
Nando Vieira

[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

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>

Referenced by

Pages