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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:36:04+00:00 2026-05-13T12:36:04+00:00

I am in the middle of migrating my application from using subdirectories for userspace

  • 0

I am in the middle of migrating my application from using subdirectories for userspace to subdomains (ie. domain.com/~user to user.domain.com). I’ve got a method in my user class currently to get the “home” URL for each user:

class User
  def home_url
    "~#{self.username}"

    # How I'd like to do it for subdomains:
    #"http://#{self.username}.#{SubdomainFu.host_without_subdomain(request.host)}"
  end
end

I’d like to update this for subdomains, but without hardcoding the domain into the method. As you can see, I am using the subdomain-fu plugin, which provides some methods that I could use to do this, except that they need access to request, which is not available to the model.

I know it’s considered bad form to make request available in a model, so I’d like to avoid doing that, but I’m not sure if there’s a good way to do this. I could pass the domain along every time the model is initialized, I guess, but I don’t think this is a good solution, because I’d have to remember to do so every time a class is initialized, which happens often.

  • 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-05-13T12:36:04+00:00Added an answer on May 13, 2026 at 12:36 pm

    While molf’s answer is good, it did not solve my specific problem as there were some instances where other models needed to call User#home_url, and so there would be a lot of methods I’d have to update in order to pass along the domain.

    Instead, I took inspiration from his last paragraph and added a base_domain variable to my app’s config class, which is the set in a before_filter in ApplicationController:

    module App
      class << self
        attr_accessor :base_domain
      end
    end
    
    class ApplicationController < ActionController::Base
      before_filter :set_base_domain
    
      def set_base_domain
        App.base_domain = SubdomainFu.host_without_subdomain(request.host)
      end
    end
    

    And thus, when I need to get the domain in a model, I can just use App.base_domain.

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

Sidebar

Related Questions

I am in the middle of migrating from Linq2Sql to Entity Framework and I
We're in the middle of migrating from a windows & SQL 2000 box to
We have a fairly robust system using NHibernate, we're in the middle of migrating
I port a middle-sized application from C to C++. It doesn't deal anywhere with
Middle-tier component will execute the data access routines in application. The component will call
I'm in the middle of building a pretty big site using asp.net (forms if
I have a middle size query with 500.000 registers from an Oracle to an
Right now, I'm in the middle of actually building a Project Management application, and
I am in the middle of moving a permission system from PHP to MySQL
I am in the middle of design an application to issue and store invoices

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.