Rails: best practice to scope queries based on subdomain?

后端 未结 5 1491
傲寒
傲寒 2020-12-24 04:17

I\'m working on a Rails (currently 2.3.4) app that makes use of subdomains to isolate independent account sites. To be clear, what I mean is foo.mysite.com should show the f

5条回答
  •  无人及你
    2020-12-24 04:20

    You might be better of having a database per account and switching the database connection based on the subdomain.

    In addition to the above link if you have a model (in your case Account) that you want to use the default database just include establish connection in the model.

    class Account < ActiveRecord::Base
    
      # Always use shared database
      establish_connection  "shared_#{RAILS_ENV}".to_sym
    

提交回复
热议问题