Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create an admin subdomain to manage subdomains in Rails
    primarykey
    data
    text
    <p>I am using AuthLogic and the subdomain method that dhh covered in <a href="http://37signals.com/svn/posts/1512-how-to-do-basecamp-style-subdomains-in-rails" rel="nofollow noreferrer">this blog post</a>, everything is working great, and as expected. What I'm trying to figure out is how to create a subdomain like 'admin' or 'host' that will have a user authenticated from AuthLogic (this may be trivial and unnecessary to mention) that will manage the subdomains. So basically, all subdomains will act normally, except admin.site.com which will go to its own controller and layout..</p> <p>dhh suggested just throwing in an exception to redirect, but I'm not sure where that goes, it didnt seem that simple to me, any ideas?</p> <p><strong>EDIT</strong> I think that the fact I am using AuthLogic is important here, because the subdomain logic isnt forwarding users anywhere, once authenticated AuthLogic sends the user to /account - so my question may be related to how do I tell AuthLogic to a different spot if the user is a root user, logging into the admin subdomain..</p> <p>Here is the code we have implemented thus far</p> <blockquote> <p><strong>Company Model</strong></p> </blockquote> <pre><code>class Company &lt; ActiveRecord::Base has_many :users has_many :brands, :dependent =&gt; :destroy validates_presence_of :name, :phone, :subdomain validates_format_of :subdomain, :with =&gt; /^[A-Za-z0-9-]+$/, :message =&gt; 'The subdomain can only contain alphanumeric characters and dashes.', :allow_blank =&gt; true validates_uniqueness_of :subdomain, :case_sensitive =&gt; false validates_exclusion_of :format, :in =&gt; %w( support blog billing help api www host admin manage ryan jeff allie), :message =&gt; "Subdomain {{value}} is not allowed." before_validation :downcase_subdomain protected def downcase_subdomain self.subdomain.downcase! if attribute_present?("subdomain") end end </code></pre> <blockquote> <p><strong>SubdomainCompanies Module</strong></p> </blockquote> <pre><code>module SubdomainCompanies def self.included( controller ) controller.helper_method(:company_domain, :company_subdomain, :company_url, :company_account, :default_company_subdomain, :default_company_url) end protected # TODO: need to handle www as well def default_company_subdomain '' end def company_url( company_subdomain = default_company_subdomain, use_ssl = request.ssl? ) http_protocol(use_ssl) + company_host(company_subdomain) end def company_host( subdomain ) company_host = '' company_host &lt;&lt; subdomain + '.' company_host &lt;&lt; company_domain end def company_domain company_domain = '' company_domain &lt;&lt; request.domain + request.port_string end def company_subdomain request.subdomains.first || '' end def default_company_url( use_ssl = request.ssl? ) http_protocol(use_ssl) + company_domain end def current_company Company.find_by_subdomain(company_subdomain) end def http_protocol( use_ssl = request.ssl? ) (use_ssl ? "https://" : "http://") end end </code></pre> <blockquote> <p><strong>Application Controller</strong></p> </blockquote> <pre><code>class ApplicationController &lt; ActionController::Base include SubdomainCompanies rescue_from 'Acl9::AccessDenied', :with =&gt; :access_denied helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details helper_method :current_user_session, :current_user, :current_company_name filter_parameter_logging :password, :password_confirmation before_filter :check_company_status protected def public_site? company_subdomain == default_company_subdomain end def current_layout_name public_site? ? 'public' : 'login' end def check_company_status unless company_subdomain == default_company_subdomain # TODO: this is where we could check to see if the account is active as well (paid, etc...) redirect_to default_company_url if current_company.nil? end end 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. 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