Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme: used to_prepare instead of to_complete for tenant reset on console reload #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,13 @@ end
When using `config.require_tenant` alongside the `rails console`, a nice quality of life tweak is to set the tenant in the console session in your initializer script. For example in `config/initializers/acts_as_tenant.rb`:

```ruby
SET_TENANT_PROC = lambda do
if defined?(Rails::Console)
puts "> ActsAsTenant.current_tenant = Account.first"
ActsAsTenant.current_tenant = Account.first
end
end

Rails.application.configure do
if Rails.env.development?
# Set the tenant to the first account in development on load
config.after_initialize do
SET_TENANT_PROC.call
end

# Reset the tenant after calling 'reload!' in the console
ActiveSupport::Reloader.to_complete do
SET_TENANT_PROC.call
if Rails.env.development? && defined?(Rails::Console)
# set the current_tenant during console startup and after calling reload!
# note: reload! calls the to_prepare callback twice
ActiveSupport::Reloader.to_prepare do
puts ">>> Setting ActsAsTenant.current_tenant = Account.first"
ActsAsTenant.current_tenant = Account.first
end
end
end
Expand Down