Hi,

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 = FilterDictionary.new(filter_string)
        request.path_parameters[:filter_ids] = filter_dictionary.ids
        return true
      end
      false
    end
  end
end


the automated route test helpers 
(https://github.com/rails/rails/blob/77627c5aa3b9aeb68a53ad4a700f5003f2f24089/actionpack/lib/action_dispatch/testing/assertions/routing.rb)
 
 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: 
https://github.com/rails/rails/blob/77627c5aa3b9aeb68a53ad4a700f5003f2f24089/actionpack/lib/action_dispatch/routing/mapper.rb#L939

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?

Thanks


ps
if you're interested about the context where I run in to this: 
http://teotti.com/one-url-segment-serving-different-resources-with-ruby-on-rails-route-constraints#hack-for-adventurous-people

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to