简体   繁体   中英

Model with acts_as_tenant fails validation after Rails 5 update

rails 5.2.1 ruby 2.5.1

My Model

class InputForm < ApplicationRecord
 acts_as_tenant(:tenant)
end

InputForm.validators shows

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

This is not allowing me to create the InputForm without tenant.

Note : I don't have any config setup (config.require_tenant = true ) or file like config/initializers/acts_as_tenant.rb

What i'm doing wrong ?

Have you tried the optional: true options when specifying acts_as_tenant?

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

OR

You can configure your rails 5 application like so

# 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

Responded here as well.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM