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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:51:23+00:00 2026-06-18T05:51:23+00:00

I’m trying to determine how to do two simple tasks: I would like to

  • 0

I’m trying to determine how to do two simple tasks:

  1. I would like to load all of a Rails Apps’ models from the context of a Gem. For example say the Rails application is a blog and has authors, posts and comments. I would like the included gem to find, without knowing they exist, those models.

  2. Again, from the context of a loaded gem, I would like to have the rails models available to me; So for example I could call Author.first, without knowing Authors exist, and I would like to have that information available to the gem.

So to summarize this question. From the context of a gem, how does one load all models of a rails project, and have access to those models?

This is my fast hack:

module ActiveTest
  class Base
    def listme
      ::ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
    end
  end
end


1.9.3-p286 :005 > a = ActiveTest::Base.new
 => #<ActiveTest::Base:0x007f8882bdd460> 
1.9.3-p286 :006 > a.listme
    NameError: uninitialized constant ActiveRecord
  • 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-18T05:51:24+00:00Added an answer on June 18, 2026 at 5:51 am

    Using ActiveSupport

    models = Dir["#{Rails.root}/app/models/**/*.rb"].map do |f|
      f.chomp('.rb').camelize # works with namespaces e.g. Foo::Bar::MyClass
    end
    

    If you want to turn those strings into the actual Class objects, tack on a constantize right after camelize

    camelize docs

    constantize docs

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I would like to count the length of a string with PHP. The string

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.