[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/10/2009 at 02:10PM PDT, ID: 24641358 | Points: 500
[x]
Attachment Details

How can I configure rails routing rules based on hostname?

Asked by tero22 in Apache Web Server, Ruby Scripting Language, RubyOnRails

Tags: rails, ruby on rails

Hello,

I would like to configure rails routing rules based on hostname.  From browsing the web I tried adding the following code to my environment.rb:

module ActionController
  module Routing
    class RouteSet
      def extract_request_environment(request)
        { :method => request.method, :hostname => request.server_name }
      end
    end
    class Route
      alias_method :old_recognition_conditions, :recognition_conditions
      def recognition_conditions
        result = old_recognition_conditions
        result << "conditions[:hostname] === env[:hostname]" if conditions[:hostname]
        Rails.logger.debug "result = #{result}"
        result
      end
    end
  end
end

Then in my routes.rb, I added:
  map.connect ':id', :controller => 'landing', :action => 'index', :conditions => { :hostname => 'blah' }

Yet the routing rule seems to be enacted regardless of the hostname.  Furthermore the debug code I added to recognition_conditions never seems to get called.
[+][-]08/19/09 05:09 AM, ID: 25131652

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625