Rails 3: subdomain routes

I am trying to convert some subdomain routes from rails 2.3.x (with the subdomain_routes plugin), like these:

map.subdomain :biz do |biz| biz.resources :users biz.resources :projects biz.root :controller => 'home' end 

with these routes, I got the following URLs:

 http://biz.example.com/users # :controller => 'biz/users', :action => 'index', :subdomain => 'biz' 

with rails3, subdomain_routes does not exist, and I cannot create the same routes (even if I read that this is possible). Tried with this:

 scope :module => :biz, :as => :biz do constraints(:subdomain => 'biz') do resources :users resources :projects root :to => 'Biz::HomeController#index' end end 

but when I try on the console I don’t get a subdomain, so for: app.biz_users_url # http://www.example.com/users , but not http://biz.example.com/users

I also read / watched these resources, but there is no solution to my specific problem:

http://railscasts.com/episodes/221-subdomains-in-rails-3 http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up

any suggestions? thanks in advance;)

but.

+7
source share
2 answers

the routes above are correct, the main problem was that they did not work with locahost. using http://lvh.me (a virtual domain that points to 127.0.0.1) as a fake domain

+9
source

You can get the URL with the subdomain by making the following call to app.biz_users_url (subdomain: 'biz')

+1
source

All Articles