Sergey Mell
Sergey Mell

Reputation: 8040

Gem needs to be required manually

I've created a gem. You can see the full source code here: https://github.com/agilie/instagram_api_gem (in any case, not advertising)

However, when I use it in the Rails project

# Gemfile
gem 'instagram_api_client'

it doesn't work untill a manually require it somewhere in the initializers like

require 'instagram_api'

Why does this happen? I want it to work without any manual requires like other rails gems work.

Upvotes: 1

Views: 492

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 120990

It does not conform Rails autoloading rules. Create a file instagram_api_client.rb with a content

require 'instagram_api'

in the top level of lib folder. That should do the trick.

For gems, the name of the file to be loaded automatically should be exactly equal to the name of the gem.


Or, as suggested by @TomLord, one might simply specify

gem 'instagram_api_client', require: 'instagram_api'

in the Gemfile itself.

Upvotes: 3

Related Questions