Alexander Dymo
2006-Nov-29 18:57 UTC
wrong url construction with edge rails under certain conditions
Hi! I''ve noticed the new behavior that was not seen in stable Rails. Using edge Rails (from today) I have the following problem. Example situation: * user is executing GET request to /sprint/show/205 * there''s a route: map.connect ''sprint/show/:sprint'', :controller => ''task'', :action => ''index'' * in task/index.rhtml template we have: <%= link_to "Break Me", :action => ''foo'', :params => { :sprint => 1 } %> Problem: * on generated page the link is: <a href="/task/foo">Break Me</a> without the sprint parameter Why? * url_for is used to build the URL * url_for calls the URL rewriter (UrlRewriter::rewrite_path) to get the URL path string * rewriter asks the request about path parameters and in our case it gets {:controller => ''task'', :action => ''index'', :sprint => 205 } * rewriter asks the route to generate the url by passing path parameters as "recall" argument to Route::generate(options, recall, method) * generate method "recalls" those from the path, including "sprint" which is wrong in this case! The conclusion is that in edge Rails parameters to the url_for can not have the same name as symbols in the route. I''m not sure at this point if that''s a bug or "feature" of new Rails. I can easily fix the situation just by using :params => {:sprint_id => 1} so maybe this issue is an another thing that should be in the upgrade guide... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jamis Buck
2006-Nov-29 19:09 UTC
Re: wrong url construction with edge rails under certain conditions
Alexander, Don''t put things in :params => {}. Just do :sprint => 1 directly. In other words: link_to "...", :action => "foo", :sprint => 1 - Jamis On Nov 29, 2006, at 11:57 AM, Alexander Dymo wrote:> > Hi! > I''ve noticed the new behavior that was not seen in stable Rails. > Using edge Rails (from today) I have the following problem. > > Example situation: > * user is executing GET request to /sprint/show/205 > * there''s a route: > map.connect ''sprint/show/:sprint'', :controller => ''task'', :action > => ''index'' > * in task/index.rhtml template we have: > <%= link_to "Break Me", :action => ''foo'', :params => { :sprint => > 1 } %> > > Problem: > * on generated page the link is: <a href="/task/foo">Break Me</ > a> without > the sprint parameter > > Why? > * url_for is used to build the URL > * url_for calls the URL rewriter (UrlRewriter::rewrite_path) to > get the > URL path string > * rewriter asks the request about path parameters and in our > case it gets > {:controller => ''task'', :action => ''index'', :sprint => 205 } > * rewriter asks the route to generate the url by passing path > parameters > as "recall" argument to Route::generate(options, recall, method) > * generate method "recalls" those from the path, including > "sprint" which > is wrong in this case! > > The conclusion is that in edge Rails parameters to the url_for can > not have > the same name as symbols in the route. > I''m not sure at this point if that''s a bug or "feature" of new > Rails. I can > easily fix the situation just by using :params => {:sprint_id => 1} so > maybe this issue is an another thing that should be in the upgrade > guide... > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com > To unsubscribe from this group, send email to rubyonrails-core- > unsubscribe@googlegroups.com > For more options, visit this group at http://groups.google.com/ > group/rubyonrails-core?hl=en > -~----------~----~----~----~------~----~------~--~--- >
Alexander Dymo
2006-Nov-29 23:19 UTC
Re: wrong url construction with edge rails under certain conditions
On Wednesday 29 November 2006 21:09, Jamis Buck wrote:> Don''t put things in :params => {}. Just do :sprint => 1 directly. > In other words: > link_to "...", :action => "foo", :sprint => 1Well, that doesn''t quite work. I still have the url without the sprint parameter. I guess that''s because :sprint is still passed in the recall option of Route::generate(options, recall, method) Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---