如何将带有公寓宝石的Rails应用正确部署到Heroku?

时间:2018-12-17 16:38:48

标签: heroku heroku-postgres apartment-gem

我已经在5.2 Rails应用程序中使用Postgresql 10安装了2.2版公寓gem,并且在我的本地环境中一切正常。

当我部署到Heroku时,构建成功,但是我无法访问该站点。我的日志显示找不到公寓租户的错误

Apartment::TenantNotFound (One of the following schema(s) is invalid: "<heroku app name>" "public"):

我正在使用Devise进行身份验证,并在主应用程序控制器中添加了一个Tenant开关

 def after_sign_in_path_for(resource)

  Apartment::Tenant.switch(resource.account.subdomain) do
    root_url(:subdomain => resource.account.subdomain)
  end
end

在我的apartment.rb文件中,我使用了以下配置(省略了注释项)

require 'apartment/elevators/subdomain'
Apartment.configure do |config|
    config.excluded_models = %w{ Account User}
    config.tenant_names = lambda { Account.pluck :subdomain }
    config.db_migrate_tenants = false
    config.use_schemas = true
end
Apartment::Elevators::Subdomain.excluded_subdomains = %w(www app admin secure public mail pop smtp ssl sftp).freeze
Rails.application.config.middleware.insert_before Warden::Manager, Apartment::Elevators::Subdomain
Rails.application.config.middleware.use Apartment::Elevators::Subdomain

0 个答案:

没有答案