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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:28+00:00 2026-06-17T09:09:28+00:00

I’m having some trouble to namespace a module that I include in a model.

  • 0

I’m having some trouble to namespace a module that I include in a model.

in /app/models/car.rb

class Car
 include Search::Car
end

in /lib/search/car.rb

module Search
  module Car
    include ActiveSupport::Concern
    # methods in here
  end
end

in /config/application.rb

config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.autoload_paths += Dir["#{config.root}/lib/search/*"]

The weird thing is that I don’t get any errors directly when I fire up the server.
But if I refresh the browser after a while I get this error:

Expected #{Rails.root}/lib/search/car.rb to define Car

The nature of the problem indicates that it has something to do with:

/config/environments/development.rb

config.cache_classes = false

I also tried put a file search.rb directly in /lib where I define Search:

module Search
  # Put shared methods here
end

What am I doing wrong?

UPDATE:

Ok, turns out that if I rename Search::Car to Search::CarSearch it works.
Is it not possible to have Modules/Classes of the same name in a different scope?

  • 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-17T09:09:29+00:00Added an answer on June 17, 2026 at 9:09 am

    The error is coming from your autoload_paths. config.autoload_paths += Dir["#{config.root}/lib/**/"] will add all directories and their subdirectories under lib directory. meaning that you are telling rails to autoload lib/search/ directory, therefore car.rb under that directory is expected to define Car and not Search::Car. In order for rails to expect lib/search/car.rb to define Search::Car, you need to autoload lib/ directory and not lib/search. if you change you autoload to config.autoload_paths += Dir["#{config.root}/lib/"] and put search.rb in lib/ with following code:

    module Search
      require 'search/car'
    end
    

    then rails will understand and expect lib/search/car.rb do define Search::Car and referencing Car module/class in other places of your code will not reference to this car.rb.

    You should remove this line (you should only have autoload for lib directory):
    config.autoload_paths += Dir["#{config.root}/lib/search/*"]

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.