Take the 2-minute tour ×

I have written a generator which creates the following ruby file and folder:


in the test.rb file I have a Test class which looks like this:

class Test < MyCustomModule::MyCustomClass::Base

Now, I want to use its functionality in one of the show.html.erb files creating new instance like this:


but I am getting the following error:

uninitialized constant MyCustomModule::MyCustomClass::Base

I have use the following answer to link my gem and my rails application. It seems to work as I am able to use the generator, but the gem module and class are not seen in the rails application.

Could anyone tell how to fix this issue?

I have try to follow the tips posted here but still nothing changed:

  1. Adding config.autoload_paths += Dir["#{config.root}/lib/**/"] in application.rb file
  2. I have created my gem structure looking at CarrierWave gem, so the naming should be correct
  3. I try to disable config.threadsafe! but it is already disabled since config.cache_classes and config.eager_load are set to false in development

    DEPRECATION WARNING: config.threadsafe! is deprecated. Rails applications behave by default as thread safe in production as long as config.cache_classes and config.eager_load are set to true.

Also, looking at adding-asset-to-your-gems rails documentation, it is said that:


So, I have done this, and put my model class file in assets folder, but the result is the same.

The following screenshots demonstrate my real case:

  1. The screenshot below displays my gem file structure

    enter image description here

  2. Here you can see how I am loading the gem in my Rails application Gemfile:

    gem 'thumbnail_hover_effect', '0.0.3', github: 'thumbnail_hover_effec/thumbnail_hover_effec', branch: 'master'
  3. Then I am using the gem generator a ruby file with a cutstom name in app/thumbnails/test.rb folder with the following code:

    class Test < ThumbnailHoverEffect::Image::Base

    and trying to use the Test class gives me uninitialized constant ThumbnailHoverEffect::Image::Base error.

  4. Back in the gem files, these are how the thumbnail_hover_effect file looks like

    require 'thumbnail_hover_effect/version'
    require 'thumbnail_hover_effect/engine'
    require 'thumbnail_hover_effect/image'
    module ThumbnailHoverEffect
       # Your code goes here...

    and hoe the image file looks like:

     module ThumbnailHoverEffect
        class Image
share|improve this question
can you provide real-world code please? what's the exact class-name, what are the file-names? are you sure that everything get's loaded properly (i doubt it). –  phoet May 16 at 1:10
@phoet Sorry, for the late replay. I have added some real code, let me know if you need to know something else. –  gotqn May 18 at 20:45
and where is ThumbnailHoverEffect::Image::Base supposed to be coming from? –  phoet May 19 at 0:33
where is the definition of MyCustomModule::MyCustomClass::Base? –  Малъ Скрылевъ May 20 at 12:57
i'm saying that if you have an error saying uninitialized constant ThumbnailHoverEffect::Image::Base you should show the code for ThumbnailHoverEffect::Image::Base and how it's included in your code-base. –  phoet May 20 at 13:44

1 Answer 1

up vote 1 down vote accepted

From what you've posted here there is no ThumbnailHoverEffect::Image::Base defined. Rails autoloading conventions (which you should not be depending on a gem btw, more on that later) would be looking for this file in thumbnail_hover_effect/image/base.rb, but the directory structure you printed does not have that. Of course you could define the class in thumbnail_hover_effect/image.rb and it would work, but the abridged snippet you posted does not show that. So where is ThumbnailHoverEffect::Image::Base defined?

If it's in thumbnail_hover_effect/image/base.rb then that would indicate the file is not being loaded. You can sanity check this by putting a puts 'loading this stupid file' at the top of thumbnail_hover_effect/image/base.rb. That will allow you to bisect the problem by seeing whether there is a problem with your definition of the class, or whether the problem is with loading the proper files. Debugging is all about bisecting the problem.

share|improve this answer
it does not even look like there is a ThumbnailHoverEffect::Image::Base –  phoet May 20 at 22:32
Of course there is no ThumbnailHoverEffect::Image::Base - I haven't defined such class at all. I ended in this foolish situation because I am ruby newbie who decided to use a working gem structure and code as a template. –  gotqn May 21 at 17:50

Your Answer


