Forum: Ruby on Rails Routes: query parameter keys and significant keys in routes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F54510b85a9e9667b038efc239252035?d=identicon&s=25 (Guest)
on 2007-03-06 02:23
(Received via mailing list)
I'm currently facing a problem where I'd like to take parameter which
is encoded into the path portion of the URL via routes on one page,
and add it as a query parameter for a link to a subsequent page
(linked on the current page).  I would like the query parameter to be
keyed by the same key that is used on the current page in the route.
Here is the example:

map.connect '/:search_term/:foo/:bar', ........
map.connect '/:foo/:bar/:baz',  .........

I am currently on page a (the first route), and have a link to page
b(second route).  In the link_to method, I pass the key/value pair
{:search_term => 'foo'}, but it does not appear as a query parameter
on this generated link.

The code in ActionController::Routing that removes this is:

def extra_keys(hash, recall={})
  (hash || {}) { |k| k.to_sym } - (recall || {}).keys -

Hash is the newparameter options, and recall is the hash of current
parameters.  Why would you subtract recall from hash when figuring out
which keys are going to be appended as query parameter keys?

This topic is locked and can not be replied to.