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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:43:50+00:00 2026-05-27T00:43:50+00:00

I have created some classes in a module, f.i. Request (app/models/api/request.rb) class Api::Request end

  • 0

I have created some classes in a module, f.i. Request (app/models/api/request.rb)

class Api::Request
end

And now I want to check in the console does the class exist?

>> Api.const_defined?('Request')
=> false
>> Api::Request
=> Api::Request
>> Api.const_defined?('Request')
=> true

Strange, but the script cannot see the class name unless I use it in the code.
How to fix this? And if you can explain the issue, it will be great.
The project uses Rails 2.3

  • 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-27T00:43:50+00:00Added an answer on May 27, 2026 at 12:43 am

    The problem here is with the rails autoload mechanism. Basically what it does is to react to the method const_missing which you can define on every object. When this method is called, Rails looks for a file which is likely to contain a definition for the missing constant and requires it. The problem is that

    Api::Request
    

    triggers const_missing but

    Api.const_defined?('Request')
    

    does not.

    You can write your own const_defined? like this (the code would go into a rails initializer):

    def Module.autoload_const_defined?(name)
      self.const_get name
    ensure
      return self.const_defined?(name)
    end
    

    which first tries to autoload the constant.

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

Sidebar

Related Questions

I have created some extra functionality on my Linq-to-SQL classes to make things easier
I have created some simple app in Java, and 'deployed' it using Java Web
I have created some tests in my WPF application. Right now I am working
I have a python module. I want to populate some values to it at
I am learning Scala now and I want to write some silly little app
I have authored some custom classes that I would like to create using XAML:
I have created some rounded navigation tabs using CSS and am having trouble when
I have created some python code which creates an object in a loop, and
I have created some functional categories that I use to show/hide markup elements. However,
I have created some simple charts (of type FastLine) with MSChart and update them

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.