Routes: query parameter keys and significant keys in routes

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 || {}).keys.map { |k| k.to_sym } - (recall || {}).keys -
significant_keys
end

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?

Best,
Alex

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs