Clarify if rails 4.1 route constraint changing request object is a feature or a bug


I didn’t open this on github cause I am unsure if this is an intended feature or a bug.

Currently the constraint object has access to the request object and can modify its parameters. Ie.

module RouteConstraints

  class VanitySlug

    def matches?(request)
      vanity_url = request.path_parameters[:vanity_url]
      if vanity_url =~ /^filter-/
        filter_string = vanity_url.gsub(/^filter-/, '')
        filter_dictionary =
        request.path_parameters[:filter_ids] = filter_dictionary.ids
        return true


the automated route test helpers ( will not pick up the new parameter, which is why I started thinking this might be a bug. In that case passing a frozen request object to the constraint would a way to ensure the constraint responsibility.

Here’s the constraint code:

Personally when I look at the constraint I would not expect it to change the request. I’d delegate that to a request transformer.

Can somebody clarify if this is a supported feature or a bug?



if you’re interested about the context where I run in to this: