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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:11:55+00:00 2026-06-13T22:11:55+00:00

I have two namespaces, each with its own controller and presenter classes: Member::DocumentsController Member::DocumentPresenter

  • 0

I have two namespaces, each with its own controller and presenter classes:
Member::DocumentsController
Member::DocumentPresenter
Guest::DocumentsController
Guest::DocumentPresenter

Both presenters inherit from ::DocumentPresenter.

Controllers access their respective presenters without namespace specified, e.g.:

class Guest::DocumentsController < ActionController::Base
    def show
        DocumentPresenter.new(find_document)
    end
end

This usually calls presenter within same namespace. However sometimes in development environment I see base ::DocumentPresenter is being used.

I suspect the cause is that base ::DocumentPresenter is already loaded, so Rails class auto-loading doesn’t bother to look further. Is this likely the case? Can it happen in production environment too?

I can think of two solutions:

  • rename base class to DocumentPresenterBase
  • explicitly require appropriate presenter files in controller files

Is there a better solution?

  • 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-13T22:11:56+00:00Added an answer on June 13, 2026 at 10:11 pm

    You are correct in your assumptions – If you do not specify namespace, Ruby starts from current namespace and works its way up to find the class, and because the namespaced class is not autoloaded yet, the ::DocumentPresenter is found and autoloader does not trigger.

    As a solution I would recommend renaming ::DocumentPresenter to DocumentPresenterBase, because this protects you from bugs when you forget namespacing or explicit requiring somewhere.

    The second option to consider would actually be using specific namespaced classnames all over the place, but this suffers from bugs when you accidentally forget to namespace some call.

    class Guest::DocumentsController < ActionController::Base
      def show
        Guest::DocumentPresenter.new(find_document)
      end
    end 
    

    Third option would be your second – explicitly require all the classes in initializer beforehand. I have done this with Rails API which receives embedded models in JSON and Rails tends to namespace them when the actual models are not loaded yet.

    Option 3.5 You could probably trick autoloader to do the heavy lifting (though, this might seem more like a hack):

    class Guest::DocumentsController < ActionController::Base
    
      # trigger autoload
      Guest::DocumentPresenter
    
      def show
        # This should refer Guest::DocumentPresenter
        DocumentPresenter.new(find_document)
      end
    
      def show
        # As will this
        DocumentPresenter.new(find_document)
      end
    end 
    

    Still the cleanest would be to rename the base class.

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

Sidebar

Related Questions

I have a project with two namespaces, Interfaces, and Services. Each service implements its
I have two classes (class A and B) both marked with [Binding]. Currently I'm
I have two namespaces: 1) Foo.Bar 2) Another.Foo.Bar From a class in namespace 2,
I have two XmlDocuments that both have a namespace attribute specified. Both documents have
I have two classes (MVC view model) which inherits from one abstract base class.
I have a cyclical redundancy circular dependency between two classes in my project, StatusEffect
I have two xml documents with about 1000 elements in each of them and
I have two asynctask working with each other. I'm using them for creating Restaurant
i'm new to c# .Net. in my solution, two namespaces cannot see each other.
I have a WPF TabControl with two TabItems. Each TabItem contains a ListBox with

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.