Hadmut
2008-May-20 22:46 UTC
Problem with redirect_to and URL structure since upgrade to rails 2.0
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-May-21 00:08 UTC
Re: Problem with redirect_to and URL structure since upgrade to rails 2.0
You could use restful routing. http://frozenplague.net/2008/01/06/restful-routing-an-overview/ On Wed, May 21, 2008 at 8:16 AM, Hadmut <hadmut-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 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 > > > > > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hadmut
2008-May-22 20:16 UTC
Re: Problem with redirect_to and URL structure since upgrade to rails 2.0
On May 21, 2:08 am, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne
2008-May-22 20:28 UTC
Re: Problem with redirect_to and URL structure since upgrade to rails 2.0
Hadmut wrote:> On May 21, 2:08 am, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---