redirect without changing url

   Lets assume we have an url, /controller1/action1.
   In the before filter, under certain conditions, I want to route it
to /controller2/action2. without changing the url at the client side
ie I donot want to use redirect. Please help.


I would suggest using render instead of redirect.

<%= render :partial => "controller2/action2" %>

Checkout this page for more info:

class FooController < ApplicationController
  before_filter :maybe_redirect


   def maybe_redirect
      redirect_to your_url


You can do, but that's not quite beautiful ..
more over what your action2 will do after finish ? redirect ? render ?


You really need to give us more information to help. If you want just
the layout from the other action, you can use render. However, render
will not execute the code from the controller's action method; it will
only render the template. If you want to execute the code and truly
redirect, I think you are stuck changing the url. Why do you need to
do this? Let us know a little more of the situation and we might be
able to give you a better solution.

Good luck,


thanks for your replies,

I want to execute the new action as well as render the corresponding
view, without changing the url. It is a case of dynamic routing.

Following is the scenario:
Every user can have their profile on the website, whose url is
Additionally there would be an option for the user to add a domain to
point to their profile.
So for example, my profile on the website is
If I own a domain, and point it to, then should take me to the page without
changing the url.
In the before filter function, I check if the url is not, then
it is mapped to the corresponding user, and then I need to go to the
corresponding controller and action.


can metal or rack be helpful in this?

can metal or rack be helpful in this?