Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9232741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:23:10+00:00 2026-06-18T06:23:10+00:00

Gems ruby 1.9.3 rails 3.2.11 devise 2.2.3 acts_as_tenant 0.2.9 Code All my models are

  • 0

Gems

ruby 1.9.3
rails 3.2.11
devise 2.2.3
acts_as_tenant 0.2.9

Code

All my models are scoped by a domain_id:

class User < ActiveRecord::Base
  acts_as_tenant(:domain)
  #...
end

Then, in my application_controller, I set the current tenant from the domain:

class ApplicationController < ActionController::Base
  set_current_tenant_through_filter
  before_filter :set_tenant
  protect_from_forgery
  #...

  def set_tenant
    #...
    @domain = Domain.find_or_create_by_name(request.host)
    set_current_tenant(@domain)
  end
end

All works well for all models except for sessions: Everytime a page is loaded, it will log-out the first user who load a page with another tenant. By loading this page, it will log-out the first user who [… etc.]

Hypothesis: when Alice visits a domain, Rails loads current_tenant=alice_domain (ok). All works as expected, until Bob visits another domain, load current_tenant=bob_domain. When Alice refreshes her page, Rails still has current_tenant==bob_domain. Rails checks session: Alice does not exist with bob_domain scope, so Devise forces Alice logout. Then application_controller sets current_tenant=alice_domain… which logs-out Bob.

Dirty workaround: do not use acts_as_tenant in user model, scope users by domain myself in every controllers, then overwrite devise to scope login and registration by domain. And I’m unsure how to get Devise aware of current domain in sessions stuff. By the way, replacing acts_as_tenant by a manual default_scope in user falls in the same strange bugs. It seems very dirty to go this way.

I’m looking for a clean solution for days. I would be very grateful for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:23:11+00:00Added an answer on June 18, 2026 at 6:23 am

    Fixed, in application_controller, change

    before_filter :set_tenant
    

    to

    prepend_before_filter :set_tenant
    

    in order to default_scope everything, including User, before Devise checks the user’s session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Ruby On Rails 3 and Webrick issue $ rails server /Users/Vineeth/.rvm/gems/ruby-1.9.3-p194/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require':
I encounter identical issues with some Ruby gems in Rails application. When I use:
I am following Lynda ruby on rails tutorial. Here is the code I have
Vitals: ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux] Rails 3.2.7 Devise 2.1.2 The GET /users/sign_in
I have created a new rails app (3.2.8) using Devise. All is setup properly,
Error: C:/Ruby193/lib/ruby/gems/1.9.1/gems/devise-1.0.11/lib/devise.rb:89:in '': undefined method 'weeks' for 2:Fixnum (NoMethodError) That error is thrown whenever
Upon launching a sinatra app, I get the following error message: /home/matt/.rvm/gems/ruby-1.9.3-p125/gems/backports-2.5.1/lib/backports/tools.rb:310:in `require': cannot
I'm developing two Ruby gems, one is a framework, the other is an application.
there is a list of ruby gems for twitter could anybody recommend me one
Using Your Ruby Gem(s) You will need to add /home/username/ruby/gems to the include path.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.