English 中文(简体)
• 如何将一个完整的领域绘制到底线铁路附属账户?
原标题:How to map a full domain to a subdomain-based Rails app account?

I m 建造铁路,预计到违约时,其选择的子公司就设立了用户账户。 作为一种选择,他们将能够把自己的全部领域绘制到自己的账户。

到目前为止,这是我如何做的事情。 我正在使用subdomain-fu,以控制路边:

# routes.rb
map.with_options :conditions => {:subdomain => true} do |app|
  app.resources # User s application routes are all mapped here
end

map.with_options :conditions => {:subdomain => false} do |www|
  www.resources # Public-facing sales website routes are mapped here
end

除此以外,我还利用,通过子域或全域进入账户:

before_filter :set_current_account

def set_current_account
  if request.host.ends_with? current_domain
    # via subdomain
    @current_club = Club.find_by_subdomain(current_subdomain)
  else
    # via full domain
    @current_club = Club.find_by_mapped_domain(request.host)
  end
end

我 have了建设这一进程的进程,但我已经看到,我会陷入路上的问题。 如果request.host 是一些随机的.com域,那么次之遥将无法通过适当的路线?

我假定这是一个不寻常的问题,那么,任何人都能够分享他们如何解决这一问题,或者我会如何混淆我的道路去做我需要做的事情?

最佳回答

我陷入了这一问题,试图在单一申请范围内做太多的工作。 你们不得不在非常困难的地方开始做条件。 我决定,有2个单独的铁路机,有野心域指用户应用,然后有<条码>www.domain.com和<条码>。 我很想知道,这并没有直接回答你的问题。

如果你在这种方法的顶端增加,我可以帮助你确定:

return @current_club if defined?(@current_club)

每当你试图进入<条码>@ 当前_club时,它就得 t。

问题回答

您可以撰写一份“Rack”中层电器,将田地转换成子主,然后打上铁路应用。

class AccountDetector
  def initialize(app)
    @app = app
  end

  def call(env)
    account = Club.find_by_mapped_domain(env["HTTP_HOST"])
    if account
      env["HTTP_HOST"] = "#{account.subdomain}.yourdomain.com"
    end

    @app.call(env)
  end
end

之后添加如下内容:

config.middleware.use AccountDetector




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签