Forcing subdomains and removing subdomains

I am writing an application that will use basecamp-style subdomains ( See post ).

There are parts of the application that should always be in the subdomain , and parts that should never be in the subdomain . For example, the home page should never be in a subdomain, but blogs and posting resources should always. Keep in mind that I do not know the subdomains, as there is one account.

I configured my routes like this (example). It works well in that it matches the routes, but it's hard for me to get the application to connect to the correct locations.

MyApp::Application.routes.draw do

  # these should all route to mysubdomain.myapp.com
  # Clicking on a post from myapp.com/categories/12 should take you to mysubdomain.myapp.com/posts/14
  constraints(Subdomain) do
    resources :blogs { resources :posts }
  end

  # these should all route to myapp.com (clicking on one of these links from mysubdomain.myapp.com should go to myapp.com/categories/12)
  constraints(NoSubDomain) do
    resources :categories
  end

end

, , , ( ..) . , . .

+5
3

, , url_for, :subdomain.

. RailsCasts # 221.

Railscasts: http://railscasts.com/episodes/221-subdomains-in-rails-3

ASCIIcasts: http://asciicasts.com/episodes/221-subdomains-in-rails-3

- :

<p><%= link_to "All Blogs", root_url(:subdomain => false) %></p>  
+6

, , resource_name_url, resource_name_path.

URL (/accounts) vs url, (www.example.com/accounts).

, ,

0

, , -, , , - ( Rails conf, app), root_url, . , , base_url - , Rails-esque.

0

All Articles