Andrew Kaspick
2007-Mar-03 19:53 UTC
url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
Hello, I posted this to the main rails list (http://www.ruby-forum.com/topic/99845), but haven''t received any replies yet, so maybe this question is better suited here. Sorry if this has been brought up before, I couldn''t find any previous discussion on this. To summarize the post... When using the latest Rails (1.2.2) I''m passing an array to url_for like so... url_for :controller => ''test'', :action => ''list'', :fields => %w(a b c d) and that generates... "/test/list?fields=a%2Fb%2Fc%2Fd" params[:fields] in the action contains "a/b/c/d" When using Rails 1.1.6, the same url_for call generates... "/test/list?fields[]=a&fields[]=b&fields[]=c&fields[]=d" With this, params[:fields] contains an array like I expected. What''s the reason for the difference between the two? Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-Mar-03 23:45 UTC
Re: url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
On 3/3/07, Andrew Kaspick <akaspick@gmail.com> wrote:> > I posted this to the main rails list > (http://www.ruby-forum.com/topic/99845), but haven''t received any > replies yet, so maybe this question is better suited here. Sorry if > this has been brought up before, I couldn''t find any previous > discussion on this. > > To summarize the post... > > When using the latest Rails (1.2.2) > > I''m passing an array to url_for like so... > url_for :controller => ''test'', :action => ''list'', :fields => %w(a b c d) > > and that generates... > "/test/list?fields=a%2Fb%2Fc%2Fd"CGI.escape %w(a b c d).to_param params[:fields] in the action contains "a/b/c/d"> > When using Rails 1.1.6, the same url_for call generates... > "/test/list?fields[]=a&fields[]=b&fields[]=c&fields[]=d"Array#to_param didn''t exist in 1.1.6. Perhaps it should be removed. jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Mar-04 00:14 UTC
Re: url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
Ok, I didn''t notice the to_params method on Array. So are the results in 1.2.2 the correct results and I should be manually doing a split(''/'') on the string now? Getting an array in the params object automatically (as in 1.1.6) seems like the preferred way of doing things. This seems like a pretty major change on how the parameters are handled. I can''t seem to find anything on this in the CHANGELOG''s either. What''s the rational behind this change? If any. Thanks, Andrew On 3/3/07, Jeremy Kemper <jeremy@bitsweat.net> wrote:> On 3/3/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > I posted this to the main rails list > > (http://www.ruby-forum.com/topic/99845), but haven''t > received any > > replies yet, so maybe this question is better suited here. Sorry if > > this has been brought up before, I couldn''t find any previous > > discussion on this. > > > > To summarize the post... > > > > When using the latest Rails (1.2.2) > > > > I''m passing an array to url_for like so... > > url_for :controller => ''test'', :action => ''list'', :fields => %w(a b c d) > > > > and that generates... > > "/test/list?fields=a%2Fb%2Fc%2Fd" > > CGI.escape %w(a b c d).to_param > > > params[:fields] in the action contains "a/b/c/d" > > > > When using Rails 1.1.6, the same url_for call generates... > > > "/test/list?fields[]=a&fields[]=b&fields[]=c&fields[]=d" > > Array#to_param didn''t exist in 1.1.6. Perhaps it should be removed. > > jeremy > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jack Christensen
2007-Mar-04 00:48 UTC
Re: url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
Andrew Kaspick wrote:> Hello, > > I posted this to the main rails list > (http://www.ruby-forum.com/topic/99845), but haven''t received any > replies yet, so maybe this question is better suited here. Sorry if > this has been brought up before, I couldn''t find any previous > discussion on this. > > To summarize the post... > > When using the latest Rails (1.2.2) > > I''m passing an array to url_for like so... > url_for :controller => ''test'', :action => ''list'', :fields => %w(a b c d) > > and that generates... > "/test/list?fields=a%2Fb%2Fc%2Fd" > > params[:fields] in the action contains "a/b/c/d" > > When using Rails 1.1.6, the same url_for call generates... > "/test/list?fields[]=a&fields[]=b&fields[]=c&fields[]=d" > > With this, params[:fields] contains an array like I expected. > > What''s the reason for the difference between the two? > > Thanks, > Andrew > > > > >There are a couple tickets relating to this. There is a patch, but it hasn''t been applied yet. http://dev.rubyonrails.org/ticket/7462 http://dev.rubyonrails.org/ticket/7047 Jack --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Mar-04 00:58 UTC
Re: url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
Great, thanks for the links. Hopefully somebody from core can look at these soon and apply a fix. In the mean time, I''ll look into some of the proposed "fixes" to get around this for the time being. Andrew On 3/3/07, Jack Christensen <jack@jncsoftware.com> wrote:> > Andrew Kaspick wrote: > > Hello, > > > > I posted this to the main rails list > > (http://www.ruby-forum.com/topic/99845), but haven''t received any > > replies yet, so maybe this question is better suited here. Sorry if > > this has been brought up before, I couldn''t find any previous > > discussion on this. > > > > To summarize the post... > > > > When using the latest Rails (1.2.2) > > > > I''m passing an array to url_for like so... > > url_for :controller => ''test'', :action => ''list'', :fields => %w(a b c d) > > > > and that generates... > > "/test/list?fields=a%2Fb%2Fc%2Fd" > > > > params[:fields] in the action contains "a/b/c/d" > > > > When using Rails 1.1.6, the same url_for call generates... > > "/test/list?fields[]=a&fields[]=b&fields[]=c&fields[]=d" > > > > With this, params[:fields] contains an array like I expected. > > > > What''s the reason for the difference between the two? > > > > Thanks, > > Andrew > > > > > > > > > > There are a couple tickets relating to this. There is a patch, but it > hasn''t been applied yet. > > http://dev.rubyonrails.org/ticket/7462 > http://dev.rubyonrails.org/ticket/7047 > > > Jack > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-Mar-04 03:40 UTC
Re: url_for and arrays parameters (diffs between rails 1.1.6 and 1.2.2)
On 3/3/07, Andrew Kaspick <akaspick@gmail.com> wrote:> > Great, thanks for the links. Hopefully somebody from core can look at > these soon and apply a fix. In the mean time, I''ll look into some of > the proposed "fixes" to get around this for the time being.Jeremy and bgipsy are on the right track with #7047 and #7462. Nicholas introduced a #to_query method in http://dev.rubyonrails.org/changeset/6038that we should reuse and extend if needed. Anyone who''d like to merge the best of these patches, please do investigate and attach to #7047. Essentially, we need to preserve ''/*foo'' multi-segment routing with an array parameter as well as correctly handling array query parameters. In other words, routes = ActionController::Routing::RouteSet.new routes.draw { |map| map.connect ''/*foo'', :controller => ''dummy'' } assert_equal ''/a/b/c?bar%5B%5D=1&bar%5B%5D=2&bar%5B%5D=3'', routes.generate(:foo => %w(a b c), :bar => %w(1 2 3), :controller => ''dummy'') Requiring everyone to :foo => %w(a b c).join(''/) is a backward-incompatible answer, unfortunately. Best, jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---