All threads / Acts_As_Tentant User have access to many tenants

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Acts_As_Tentant User have access to many tenants

Tim Dowling asked in General

I've just created this enhancement for acts_as_tenant and wondering if anyone else would find this useful - https://github.com/ErwinM/acts_as_tenant/issues/231

Currently acts_as_tenant expects a single object rather than being able to access all tenants/accounts for a user. If a user can have many accounts then they jump between accounts. Use case could be a business advisor with many clients and they need to process 'X' in different client accounts. Keen for thoughts on this...

Hey Tim! I love that idea. I could see this being useful for Jumpstart Pro users. 👍 I'll leave a note on the GitHub issue for other people to find.

Thanks Chris, based on what you're saying would we need to change the gem? My implementation for finding a tenant:

def find_current_tenant
set_current_tenant(nil)
if user_signed_in?
account = current_user.accounts.first
set_current_tenant(account)
puts "current tenant: #{ActsAsTenant.current_tenant.inspect}"
else
set_current_tenant(nil)
end
end

So simply trying to return the first tenant created for that user. But then when im trying to access a record im getting a "NoMethodError (undefined method `last' for #Account:0x00007fffe9a93990):" error....

Ok I've updated the issue. i think what i posted would work for a normal rails MVC app by storing the tenant in the session. However with a rails API only app it's a no go so Im a little stuck.

@chris you already built this with jumpstart? Can i ask if you're storing the tenant in the session?

@Tim Dowling In Jumpstart Pro, tenant is stored depending on how you want your app to work. We can use the session, the URL (like basecamp does), the subdomain, or the actual domain. Session is the default since it's the least invasive and simplest option.

Thanks @chris. I was using Rails API and would have had to pass the tenant into the JWT which wasn't obvious and created complexity. I have bought a jumpstart license and have already built 1.5 modules in 3 days on what took me 1.5 months last time. I'm throwing away 6 months of code but gaining huge amounts of productivity.

It would be great to get a video on creating an autocomplete search with stimulus if you're short of ideas :)

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.