Railscast #388 Multitenancy with Scopes の手法を使用して、マルチテナンシー Rails アプリを開発しました。
POWを使用してローカルのiMacでうまく機能します。
しかし、私はそれを Heroku で動作させることができませんでした。アプリを起動すると、すぐにエラー画面が表示されます。
ログからのエラーは次のとおりです。
2013-09-05T14:54:43.374240+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/finder_methods.rb:310:in `find_with_ids': Couldn't find Tenant without an ID (ActiveRecord::RecordNotFound)
これは application_controller.rb コードです:
around_filter :scope_current_tenant
private
def current_tenant
Tenant.find_by_subdomain! request.subdomain
end
helper_method :current_tenant
def scope_current_tenant
Tenant.current_id = current_tenant.id
yield
ensure
Tenant.current_id = nil
end
ドメインの URL が正しく機能しています。しかし、念のため、コードをこれに変更してみました (特定のテナントに強制するため)。これは私のローカル iMac でも問題なく動作します。
def current_tenant
Tenant.find_by_subdomain! 'ame'
end
私の主な問題は、これをデバッグする方法がわからないことです。
ご協力いただきありがとうございます!
更新 1
ローカルで実行すると、ログから次のようになります。
10:31:05 web.1 | Processing by HomeController#index as HTML
10:31:05 web.1 | Creating scope :page. Overwriting existing method Tenant.page.
10:31:05 web.1 | Tenant Load (0.7ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'ame' LIMIT 1
10:31:05 web.1 | Completed 401 Unauthorized in 75ms