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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:40:38+00:00 2026-06-14T23:40:38+00:00

I created a Gem with models (actually, extracted it from the main project) to

  • 0

I created a Gem with models (actually, extracted it from the main project) to share amongst the projects we have in our platform.

We have dozens of models, so instead of requiring them one by one, I wrote the following code:

Gem.find_files("my_gem/models/*.rb").each { |path| require path }

I access one of the projects that has my_gem in the gem file and running rails c I get the following output:

/Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined method `has_attached_file' for #<Class:0x007fad4b93ccb8> (NoMethodError)

One of my models is using the gem paperclip, what is weird is:

  1. If I remove the line declared above to load all the models
    automatically, rails c runs fine
  2. If I try to include onlye the model that uses paperclip require
    "my_gem/models/paperclip_model"
    I receive the same error

So then I change my gem to not load any model, and when I try to reference any model from rails console, it says the class is not loaded, but then I run Gem.find_files("my_gem/models/*.rb").each { |path| require path } or require "my_gem/models/paperclip_model" ‘they work perfectly and I am able to work with the model.

Has any of you seen the same issue?

  • 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-14T23:40:40+00:00Added an answer on June 14, 2026 at 11:40 pm

    Seems that changing require for autoload solved the problem

    I changed Gem.find_files("my_gem/models/*.rb").each { |path| require path }

    for

    Gem.find_files("my_gem/models/*.rb").each do |f| 
      filename = File.basename(f, '.*')
      class_name_symbol = filename.classify.to_sym
      autoload class_name_symbol, "my_gem/models/#{filename}"
    end
    

    and now it is working.

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

Sidebar

Related Questions

I'm investigating on how validates_presence_of actually works. Suppose I have two models class Project
I have a form created using the simple_form gem which populates 2 models using
I have created a gem that adds a new method to the class ActiveRecord::Base.
I have a engine style Rails plugin from which I can create a gem
I'm trying to export data from my models to an excel spreadsheet. I have
I'm using rails-rspec gem and I have several specs (models, controllers, etc). When I
I met a problem with nested_form gem. I have 5 models: Category, Group, Parameter,
I'm trying this gem but there is a situation where 2 models should share
I have a gem that has some ActiveRecord-derived models. They are tested and work.
I have a model defined in a gem (Google::APIClient.new) and I've created an instance

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.