# Problem w/ routing constraints

**URL:** <https://www.ruby-forum.com/t/problem-w-routing-constraints/206202>\
**Category:** Rails\
**Created:** [April 25, 2011, 7:21pm UTC](https://www.ruby-forum.com/t/problem-w-routing-constraints/206202 "2011-04-25T19:21:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 25, 2011, 7:21pm UTC](https://www.ruby-forum.com/t/problem-w-routing-constraints/206202/1 "2011-04-25T19:21:53Z")

</div>

Hello,  
I am having a strange problem w/ rails 3 routing constraints. I  
have this custom class w/ a self.matches? method as such:

```auto

class PersonalizedDomain

  def self.matches?(request)
    Rails.logger.info("self.matches? NEVER CALLED!!!!")
  end

```

and in routes I use the custom Class like this:

```auto
require 'personalized_domain' #resides in lib

  constraints(PersonalizedDomain) do

     Rails.logger.info("constraints block ENTERED")
      root :to => "projects#show"
  end
```

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

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

The self.matches?(request) method never gets called and I don’t  
understand why?

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [April 29, 2011, 4:54pm UTC](https://www.ruby-forum.com/t/problem-w-routing-constraints/206202/2 "2011-04-29T16:54:28Z")

</div>

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:

```auto
# lib/personalized_domain.rb
class PersonalizedDomain
  def matches?(request)
    case request.host
    when "www.#{APP_CONFIG[:domain]}", "#{APP_CONFIG[:domain]}", nil
      false
    else
      true
    end
  end
end
```

and in routes I did this:

```auto
constraints(PersonalizedDomain.new) do
      resources :posts
      resources :personalized
  end
```
