ErwinM / acts_as_tenant

Easy multi-tenancy for Rails in a shared database setup.
MIT License
1.56k stars 264 forks source link

Is there a way to disable in the console? #309

Closed ConfusedVorlon closed 1 year ago

ConfusedVorlon commented 1 year ago

I love this gem - so firstly, thank you for creating it.

I run things with config.require_tenant = true this is brilliant, and it stops me from accidentally shooting myself in the foot.

However - it is annoying when I'm debugging in the console.

Is there a way for me to turn off require_tenant = true other than wrapping commands in a block?

e.g. ActsAsDenant.beChillForThisSessionPlease()

(syntax might vary!)

blombard commented 1 year ago

In application.rb you can do

module YourApp
  class Application < Rails::Application
    # ...
    console do
      ActsAsTenant.require_tenant = false
      # or
      ActsAsTenant.current_tenant = Tenant.first
    end
  end
end
ConfusedVorlon commented 1 year ago

That's great - thank you.

One minor change. The config isn't directly accessible (as far as I can tell), so it needs

module YourApp
  class Application < Rails::Application
    # ...
    console do
      ActsAsTenant.configure do |config|
        config.require_tenant = false
      end
    end
  end
end