Skip to content

Instantly share code, notes, and snippets.

@timrwilliams
Created October 4, 2017 14:24
Show Gist options
  • Save timrwilliams/7e61a2159111646c95ceae75df01c812 to your computer and use it in GitHub Desktop.
Save timrwilliams/7e61a2159111646c95ceae75df01c812 to your computer and use it in GitHub Desktop.
Choose an Apartment Tenant on start of IRB/Rails console (works on Heroku)
puts "What tenant do you require? "
tenant_names = Apartment.tenant_names
tenant_names.each_with_index do | tenant, index |
puts "#{index}: #{tenant}"
end
tenant_index = gets.chomp.to_i
tenant = tenant_names[tenant_index]
tenant = "public" if tenant.blank?
Apartment::Tenant.switch!(tenant)
puts "Current tenant: #{Apartment::Tenant.current}"
@timrwilliams
Copy link
Author

Designed to ensure you consciously choose what Apartment Tenant to work on when using the Rails console.

  • Add to your .irbrc file in project root
  • Commit to git & push to Heroku
  • Next time you run heroku run rails c -a my-application you will be prompted to select a tenant on console startup:
What tenant do you require?
0: public
1: tenant1
2: tenant2
1
Current tenant: tenant1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment