与acts_as_tenant型号的Rails 5更新后验证失败

问题描述 投票:1回答:1

轨5.2.1红宝石2.5.1

我的模型

class InputForm < ApplicationRecord
 acts_as_tenant(:tenant)
end

InputForm.validators节目

#<ActiveRecord::Validations::PresenceValidator:0x000000000baaae28
@attributes=[:tenant],
@options={:message=>:required}>

这不是让我没有租户创建InputForm。

注:我没有任何配置的设置(config.require_tenant = true)或者文件中像配置/初始化/ acts_as_tenant.rb

我在做什么错?

ruby-on-rails-5 multi-tenant acts-as-tenant
1个回答
1
投票

有指定acts_as_tenant当你尝试optional: true选择?

class InputForm < ApplicationRecord
  acts_as_tenant :tenant, optional: true
end

要么

你可以配置你的Rails 5应用程序,像这样

# config/application.rb
...
module YourProject
  class Application < Rails::Application
    ...
    # Make the belongs_to value as false by default in Rails 5
    config.active_record.belongs_to_required_by_default = false
    ...
  end
end

回答在这里。

https://github.com/ErwinM/acts_as_tenant/issues/196#issuecomment-460605781

© www.soinside.com 2019 - 2024. All rights reserved.