【问题标题】:Model with acts_as_tenant fails validation after Rails 5 update在 Rails 5 更新后,带有acts_as_tenant 的模型验证失败
【发布时间】:2019-01-31 04:54:14
【问题描述】:

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。

注意:我没有任何配置设置(config.require_tenant = true) 或类似 config/initializers/acts_as_tenant.rb 的文件

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails-5 multi-tenant acts-as-tenant


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多