Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: subdomain routes

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

map.subdomain :biz do |biz|
  biz.resources :users
  biz.resources :projects

  biz.root :controller => 'home'
end

with those routes, i got urls like this:

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

with rails3, there isn't subdomain_routes and I can't create the same kind of routes (even if I've read that 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 trying on console, I don't get subdomain, so for: app.biz_users_url # http://www.example.com/users but not http://biz.example.com/users

I've also read/watched these resources, but there's 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 ;)

A.

like image 206
Andrea Pavoni Avatar asked Dec 30 '10 15:12

Andrea Pavoni


2 Answers

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

like image 81
Andrea Pavoni Avatar answered Sep 30 '22 13:09

Andrea Pavoni


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

like image 45
Kadu Diógenes Avatar answered Sep 30 '22 14:09

Kadu Diógenes