acts_as_tenant 的模型在 Rails 5 更新后验证失败
Model with acts_as_tenant fails validation after Rails 5 update
rails 5.2.1 ruby 2.5.1
我的模型
class InputForm < ApplicationRecord
acts_as_tenant(:tenant)
end
InputForm.validators 显示
#<ActiveRecord::Validations::PresenceValidator:0x000000000baaae28
@attributes=[:tenant],
@options={:message=>:required}>
这不允许我在没有租户的情况下创建 InputForm。
Note : I don't have any config setup (config.require_tenant = true )
or file like config/initializers/acts_as_tenant.rb
我做错了什么?
您在指定 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
rails 5.2.1 ruby 2.5.1
我的模型
class InputForm < ApplicationRecord
acts_as_tenant(:tenant)
end
InputForm.validators 显示
#<ActiveRecord::Validations::PresenceValidator:0x000000000baaae28
@attributes=[:tenant],
@options={:message=>:required}>
这不允许我在没有租户的情况下创建 InputForm。
Note : I don't have any config setup (config.require_tenant = true ) or file like config/initializers/acts_as_tenant.rb
我做错了什么?
您在指定 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