Rails routes with constraints

I'm trying to catch UTF-8 URL. Normally, using constraints this works well. For the URL: /international-delight-iced-coffee/ the route works:

match ":post_name", :constraints => { :post_name => /.+/}}

All is well here. Where it fails is when I need to use advanced constraints:

match ":post_name", :constraints => Post.new

# inside Post.rb
  puts ">>>> Arrived at matches!"

self.matches never gets called. Any idea how to make the constraint catch?

Thanks in advanced! Justin


Do you need controller/action that you want the match to hit (below with the to param).

I've got something like this:

match "/:vanity", to: 'vanity#routing', constraints: RoutingConstraint.new

and my RoutingConstraint#matches? method is getting hit.

I tried this with your UTF-8 url and it seemed to work fine.

Your .matches? method is a class method, but you're passing Post.new as the constraint. Either replace Post.new with Post, or remove self. form the method definition.

Need Your Help

Need help implementing DataTemplate Selector [WP8.1] [WindowsPhone]

c# xaml windows-phone-8.1

I have made a simple RSS Feed app using AppStudio, and as the title suggests, I need some help on implementing DataTemplateSelector.

Location detection

google-maps google-maps-api-3

I am using geometa.js on http://www.strahlen.org/map/central.htm to detect the browser's location. Works perfect and smooth in Chrome and Firefox,