1

アプリケーションのマルチテナント側を実現するために、マルチ スキーマで PostgreSQL を使用するアプリケーションを開発しました。テナントはサブドメイン経由でチェックされますが、メイン ドメインを自分自身の登録ポイントおよび管理バックエンドとして引き続き使用できる方法を見つけようとしています。

以下は、テナントのチェックが行われていると思われるアプリケーション コントローラーです。

ここからレールキャストをたどりましたhttp://railscasts.com/episodes/389-multitenancy-with-postgresql?view=comments

class ApplicationController < ActionController::Base


protect_from_forgery

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_path, :alert => exception.message
  end

  before_filter :mailer_set_url_options

  def mailer_set_url_options
    ActionMailer::Base.default_url_options[:host] = request.host_with_port
  end

  around_filter :scope_current_tenant

private

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
 helper_method :current_user

  def current_tenant
    @current_tenant ||= Tenant.find_by_subdomain!(request.subdomain)
  end
  helper_method :current_tenant

  def scope_current_tenant(&block)
    current_tenant.scope_schema("public", &block)
  end
end

私が気づいている他の問題は、考案によるものです。マルチテナントが原因で表示され、アプリケーションコントローラーでヘルパー current_user を定義すると、デバイスからのセッションで気難しいことがわかります。何かアイデアはありますか?

4

2 に答える 2