Problem w/ routing constraints

Posted on 2011-04-25
Medium Priority
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)
    Rails.logger.info("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

     Rails.logger.info("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

clemcrock earned 0 total points
ID: 35492001
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)
    case request.host
    when "www.#{APP_CONFIG[:domain]}", "#{APP_CONFIG[:domain]}", nil

Open in new window

and in routes I did this:

constraints(PersonalizedDomain.new) do
      resources :posts
      resources :personalized

Open in new window

LVL 31

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
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: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 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