# Problem with redirect\_to and URL structure since upgrade to rails 2.0

**URL:** <https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199>\
**Category:** Rails\
**Created:** [May 21, 2008, 12:48am UTC](https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199 "2008-05-21T00:48:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hadmut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@Hadmut](https://www.ruby-forum.com/u/Hadmut)\
**Post date:** [May 21, 2008, 12:48am UTC](https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199/1 "2008-05-21T00:48:08Z")

</div>

Hi,

I have written a littel rails application with rails 1.x , and used  
something like

redirect\_to :controller =\> “aaa” , :action =\> “bbb” , :id =\> 123

within a controller to jump into a different controller’s action. It  
worked.

Since upgrade to Rails 2.0 it does not work anymore, but generates an  
error message like

Couldn’t find SomeModelClass with ID=bbb

As far as I can see the URL structure has changed from rails 1.3 to  
2.0

it was /controller/action/id  
but now is /controller/id/action

where e.g. /controller is mapped to ‘index’ and /controller/  
id is mapped to ‘show’

Does anybody know why this was changed and how to use redirect\_to  
right now?

regards

---

<div class="post-metadata">

**Author:** ![Hadmut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@Hadmut](https://www.ruby-forum.com/u/Hadmut)\
**Post date:** [May 21, 2008, 2:08am UTC](https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199/2 "2008-05-21T02:08:56Z")

</div>

You could use restful routing.

> **[frozenplague.net](http://frozenplague.net/2008/01/06/restful-routing-an-overview/)**
>
> This domain may be for sale!

On Wed, May 21, 2008 at 8:16 AM, Hadmut [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it was /controller/action/id  
> regards
> 
> >

–  
Appreciated my help?  
Recommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)

---

<div class="post-metadata">

**Author:** ![Hadmut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@Hadmut](https://www.ruby-forum.com/u/Hadmut)\
**Post date:** [May 22, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199/3 "2008-05-22T22:17:23Z")

</div>

On May 21, 2:08 am, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You could use restful routing.

Well, I had a view on that restful routing thing and found that I  
can’t use it, it breaks some  
of the functionality.

I had a special action in my rails application that gets the  
caller’s :controller, :action, and :id to enable  
returning to the page where it came from. This was easy since  
redirect\_to would take variables as  
parameters.

I do not see how this would work with restful routing, since it  
defines fixed macros for the pathes.

Who decided to use restful routing with rails?

---

<div class="post-metadata">

**Author:** ![Hadmut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@Hadmut](https://www.ruby-forum.com/u/Hadmut)\
**Post date:** [May 22, 2008, 10:28pm UTC](https://www.ruby-forum.com/t/problem-with-redirect-to-and-url-structure-since-upgrade-to-rails-2-0/138199/4 "2008-05-22T22:28:11Z")

</div>

Hadmut wrote:

> On May 21, 2:08 am, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > You could use restful routing.
> 
> Well, I had a view on that restful routing thing and found that I  
> can’t use it, it breaks some  
> of the functionality.
> 
> I had a special action in my rails application that gets the  
> caller’s :controller, :action, and :id to enable  
> returning to the page where it came from. This was easy since  
> redirect\_to would take variables as  
> parameters.
> 
> I do not see how this would work with restful routing, since it  
> defines fixed macros for the pathes.
> 
> Who decided to use restful routing with rails?

To your first question, you should have a route in your routes.rb that  
looks like:

map.connect ‘:controller/:action/:id’

That is how you want it to stay compatible with your old rails app.  
Restful routes look more like:

‘:resource\_name/:id/:optional\_action’

Where optional action is not a basic CRUD operation (new, edit, promote,  
rate, etc.) So make sure your defined routes are the right format.

Now to keep track of where a user was, you dont need to  
controller/action/id. You can capture the URI of the request. In your  
controller, you can do

def save\_location  
session[:return\_to] = request.request\_uri  
#=\> “/some/path\_to/something/123”  
end

def restore\_location  
redirect\_to session[:return\_to]  
end

So rather than controllers and actions, you simply capture the string  
url path, and it works great with redirect\_to.
