Модель с acts_as_tenant не проходит проверку после обновления Rails 5

Рельсы 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) или файла, подобного config/initializers/acts_as_tenant.rb

Что я делаю не так?

1 ответ

Решение

Вы пробовали optional: true варианты при указании act_as_tenant?

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

Другие вопросы по тегам