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 8801357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:48:49+00:00 2026-06-14T00:48:49+00:00

The acts_as_tenant gem works really well. No problems saving and retrieving data for multiple

  • 0

The acts_as_tenant gem works really well. No problems saving and retrieving data for multiple tenants. However, I ran into a challenge when I access my dev site without the subdomain.

THE PROBLEM: IF I don’t specify a subdomain, users from any tenant can still login.

Example – a user for cheese.lvh.me:3000 would not be able to log into and access data from bacon.lvh.me:3000 (and vice versa). BUT both cheese and bacon users can log into lvh.me:3000. Once logged in, the tenant scope does not apply anymore so all new inserts get a NULL account_id.

I’D LIKE TO: Prevent user login if subdomain is NOT specified.

I’m using M.Hartl’s user login method from the popular railstutorial.org.

def create
  user = User.find_by_email(params[:session][:email].downcase)
  if user && user.authenticate(params[:session][:password]) 
    sign_in user
    flash[:success] = "Welcome user!"
    redirect_to users_path
  else
    flash.now[:error] = 'Invalid email/password combination'
    render 'new'
  end
end

Would appreciate any advice.

  • 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-14T00:48:50+00:00Added an answer on June 14, 2026 at 12:48 am

    The easiest way I can think of would be to wrap the routes you don’t want accessed without a subdomain in a subdomain constraint:

    constraints(SubdomainRequired) do
      # routes go here
    end
    

    This SubdomainRequired constant is best, I think, defined within the lib/constraints directory of your application, in a file named after the class (lib/constraints/subdomain_required.rb):

    class SubdomainRequired
      def self.matches?(request)
        request.subdomain.present?
      end
    end
    

    Then it’s simply a matter of requiring this constraint at the top of your routes file:

    require 'constraints/subdomain_required'
    

    If the subdomain is present with this, then the route will be found. If the request is not made with a subdomain then it will not be found.

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

Sidebar

Related Questions

I'm using acts_as_audited gem in Ruby it works fine. When I created, updated or
I'm using the acts_as_taggable_on gem to tag ads. It works fine, but I need
I am using the acts_as_tenant gem to manage multi-tenancy, and I'm using devise to
I'm using acts-as-messageable , a rails gem, in an app i have. However in
I want to use acts-as-taggable-on gem for my rails app. (rails 3.0.10 and ruby
I created an app that acts as a launcher, which works as expected, but
I'm building a website that acts as a portfolio for a companies advertising works.
I'm using the acts_as_taggable_on gem on a Rails (Ruby 1.9.3) project. I provide a
I'm using acts_as_nested_set on a model which is called node. There are multiple lists
I am using the acts_as_taggable_on gem and would like to add a method to

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.