dhh建议只是引入一个例外来重定向,但是我不确定那里发生了什么,对我来说这似乎不是很简单,任何想法?
编辑
我认为我使用AuthLogic的事实在这里非常重要,因为子域逻辑不会在任何地方转发用户,一旦经过身份验证,AuthLogic会将用户发送到/ account – 所以我的问题可能与如何告知AuthLogic不同的地点有关user是root用户,登录admin子域.
这是我们迄今为止实现的代码
Company Model
class Company < ActiveRecord::Base has_many :users has_many :brands,:dependent => :destroy valIDates_presence_of :name,:phone,:subdomain valIDates_format_of :subdomain,:with => /^[A-Za-z0-9-]+$/,:message => 'The subdomain can only contain Alphanumeric characters and dashes.',:allow_blank => true valIDates_uniqueness_of :subdomain,:case_sensitive => false valIDates_exclusion_of :format,:in => %w( support blog billing help API www host admin manage ryan jeff allIE),:message => "Subdomain {{value}} is not allowed." before_valIDation :downcase_subdomain protected def downcase_subdomain self.subdomain.downcase! if attribute_present?("subdomain") endend
SubdomainCompanIEs Module
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 << subdomain + '.' company_host << company_domain end def company_domain company_domain = '' company_domain << 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
Application Controller
class ApplicationController < ActionController::Base include SubdomainCompanIEs rescue_from 'Acl9::AccessDenIEd',:with => :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 endend解决方法 查看 subdomain-fu,它允许您根据子域路由到不同的控制器和 *** 作.关于这个问题我做了 Railscasts Episode.
它可能看起来像这样.
# in routes.rbmap.manage_companIEs '',:controller => 'companIEs',:action => 'index',:conditions => { :subdomain => "admin" }
这需要在路由列表中足够高,以便在它之前没有其他匹配.
总结以上是内存溢出为你收集整理的ruby-on-rails – 如何创建管理子域以管理Rails中的子域全部内容,希望文章能够帮你解决ruby-on-rails – 如何创建管理子域以管理Rails中的子域所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)