Problem w/ routing constraints

Posted on 2011-04-25
Last Modified: 2012-05-11
   I am having a strange problem w/ rails 3 routing constraints.   I
have this custom class w/ a self.matches? method as such:

class PersonalizedDomain

  def self.matches?(request)"self.matches? NEVER CALLED!!!!")

Open in new window

and in routes I use the custom Class like this:

require 'personalized_domain' #resides in lib

  constraints(PersonalizedDomain) do"constraints block ENTERED")
      root :to => "projects#show"

Open in new window

and in application.rb, I load my lib paths:

config.autoload_paths += %W(#{config.root}/lib)

Open in new window

The self.matches?(request) method never gets called and I don't
understand why?
Question by:clemcrock

    Accepted Solution

    SOLUTION:  Here's an update - I did figure out why my custom constraint wasn't working correctly and here's the changes I made:

    In PersonalizedDomain I changed the self.matches? method from a class method to an instance method as such:

    # lib/personalized_domain.rb
    class PersonalizedDomain
      def matches?(request)
        when "www.#{APP_CONFIG[:domain]}", "#{APP_CONFIG[:domain]}", nil

    Open in new window

    and in routes I did this:

    constraints( do
          resources :posts
          resources :personalized

    Open in new window

    LVL 31

    Expert Comment

    by:James Murrell
    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
    In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below:…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now