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

  • Home
  • SEARCH
  • 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 8982425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:34:33+00:00 2026-06-15T20:34:33+00:00

building a devise rails app with user accounts as subdomains Im unable to figure

  • 0

building a devise rails app with user accounts as subdomains Im unable to figure out how to redirect to a default ( default.domain.com) subdomain when the subdomain a user visits is non existant.

For example:

  • user.domain.com works ( user exists in database )
  • user2.domain.com fails ( user not in database ) and should be redirected to default.domain.com

How can this be accomplished?
Im using below code but the redirect based on Rails.env gets in a never ending loop 🙁

class ApplicationController < ActionController::Base
  protect_from_forgery

  layout "application"
  before_filter :account

  def account
    @user     = User.where(:subdomain => request.subdomain).first || not_found
  end

  def not_found
      # next 2 lines is a temp solution--- >
      raise ActionController::RoutingError.new('User Not Found')
      return

      # --- > this below fails results in endless loop
      if Rails.env == "development"
        redirect_to "http://default.domain.dev:3000"
        return
      else
        redirect_to "http://default.domain.com"
      end
    end
end
  • 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-15T20:34:35+00:00Added an answer on June 15, 2026 at 8:34 pm

    Not sure there is going to be a particularly nice way to do this and it’s not easy to make a proper judgement here without seeing the bigger picture, but, maybe you should store the default domain as a constant somewhere and then check this before redirecting, to break the loop, as it were!

    Something like this would be better;

    class ApplicationController < ActionController::Base
      protect_from_forgery
    
      layout "application"
      before_filter :account
    
      def account
        @user = User.where(:subdomain => request.subdomain).first
    
        if @user.nil? and DEFAULT_URL =~ request.subdomain
          port = request.server_port == 80 ? '' : ":#{request.server_port}"
          redirect_to "http://#{DEFAULT_URL}#{port}"
        end
      end
    
    end
    

    You get the general idea, you could set DEFAULT_URL in an initializer..

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

Sidebar

Related Questions

I'm building a prelaunch signup site with this tutorial. http://railsapps.github.com/tutorial-rails-prelaunch-signup.html . After a user
I'm building an app in Rails 3. I currently have a user model which
I'm building a Rails 3 app using Devise, with Capybara for UI testing. The
I'm building a basic app with Rails 3.2 and Devise 2.0. I've create a
I'm building a (Rails-based) web service with a mobile app (iPhone) as frontend. In
Im building a Rails 3 app, and have an Observer... in the observer I
I am building a rails application using devise for authentication - including :confirmable functionality.
I'm building an app which holds the User data in a separate (remote) database.
I'm building a rails3 application (hosted on Heroku) and I'm using devise for user
I'm currently building a rails platform and I've used devise for authentication and now

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.