Topic: Conditional Routes in routes.rb

Hey everybody,

we are hosting two domains from a single application (lets say domain1.com and domain2.net). What we are trying to do is to have different name routes in both domains?

For example:   
www.domain1.com/entries  (in view we are calling posts_path)
www.domain2.net/articles (in view we are calling posts_path)

but it will show the same results on both domains.

I've found these articles covering this problem:
http://www.buildingwebapps.com/articles … g-in-rails
http://www.smallroomsoftware.com/articl … n-hostname


OUR routes.rb file looks like this:

map.resources :posts, :as => "entries", :conditions => {:domain => 'domain1.com'}
map.resources :posts, :as => "articles", :conditions => {:domain => 'domain2.net'}

If I call posts_path on domain1.com  everything is fine and the route generated is www.domain1.com/entries
but if I call posts_path from domain2.net   route generated is www.domain2.net/entries

(Routing Error - No route matches "/entries"  with {:subdomain=>nil, :request_uri=>"/entries", :remote_ip=>"xx.xx.xx.xx", :protocol=>"http://", :content_type=>nil, :host=>"domain2.net", :accepts=>"text/html,application/xml,*/*", :method=>:get, :domain=>"domain2.net", :port=>3000})

it should be www.domain2.net/articles

We can't figure out why the second ':as' parameter was ignored even when the domain is domain2.net and conditions is satisfied.

Any help would be much appreciated!

Cheers Pete

Re: Conditional Routes in routes.rb

What does your log say? I'm not sure if you're in production or not with this app yet, but if it's still in development mode, then take a look at the development.log in the log directory of your Rails app.

Re: Conditional Routes in routes.rb

Also, paste the results of "rake routes".