Model with acts_as_tenant fails validation after Rails 5 update

298 views Asked by At

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 ?

1

There are 1 answers

0
Sairam Suresh On BEST ANSWER

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