Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is pretty similar to what you're looking for: <a href="http://maxresponsemedia.com/rails/setting-up-user-subdomains-in-rails-3/" rel="nofollow">http://maxresponsemedia.com/rails/setting-up-user-subdomains-in-rails-3/</a>.</p> <p><strong>Edit</strong></p> <p>It appears that the link is now dead (which is why we should post more than just links!), but I was able to find it in the WayBackMachine. Here are the code examples that it had.</p> <p>First, we define a couple of constraints for subdomains and the root domain:</p> <pre><code># /lib/domains.rb class Subdomain def self.matches?(request) request.subdomain.present? &amp;&amp; request.subdomain != "www" &amp;&amp; request.subdomain != "" end end class RootDomain @subdomains = ["www"] def self.matches?(request) @subdomains.include?(request.subdomain) || request.subdomain.blank? end end </code></pre> <p>Then, in our routes.rb, we direct the subdomains to a websites controller, but any requests to domains related to the main site get sent to the static pages that are configured for the app. </p> <pre><code># config/routes.rb # a bunch of other routes... # requiring the /lib/domains.rb file we created require 'domains' constraints(Subdomain) do match '/' =&gt; 'websites#show' end constraints(RootDomain) do match '/contact_us', :to =&gt; 'static_pages#contact' match '/about', :to =&gt; 'static_pages#about' match '/help', :to =&gt; 'static_pages#help' match '/news', :to =&gt; 'static_pages#news' match '/admin', :to =&gt; 'admin#index' end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload