Multitenancy with Rails by Ryan Bigg

Multitenancy with Rails by Ryan Bigg

Author:Ryan Bigg [Bigg, Ryan]
Language: eng
Format: azw3
Published: 2015-08-07T16:00:00+00:00


By having this middleware located here, the things should be well on their way to being scoped. Let’s find out if they’re there by running the test again. When we do that, we’ll see the first test fails like this:

Failure/Error: visit main_app.things_url(:subdomain => account_b.subdomain) ActiveRecord::RecordNotFound: Couldn't find Subscribem::Account with id=<id>

This test is failing because it can’t find an account. That much is pretty obvious from the error message. But why can’t it find an account? For that answer, we must look deeper. This issue is actually caused by the schema switching stuff we have just implemented. The root of this problem is that the schema lookup path no longer contains the schema which contains the accounts: the public schema.

To fix that problem, we can exclude some models from Apartment’s scoping. We only need to exclude the Subscribem::Account model for now, but later on we’ll need to do the Subscribem::Member and Subscribem::User too, so let’s exclude both of these models now with these lines in a new file called config/initializers/apartment.rb:

Apartment.excluded_models = ["Subscribem::Account", "Subscribem::Member", "Subscribem::User"]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.