0

I have a set of files that are in the lib directory of a Ruby on Rails application.

I have a model that needs to use these files. In my model I have the following:

require_relative '../../some_path_to_file_without_extention'

(Side note; I would love to know a way to require all the files, instead of require_relative for each file).

The file that I require_relative has the following require in it.

require "bindata"

When I try to access functions from the require_relative file I get the following error:

LoadError: cannot load such file -- bindata

This is happening for other gems that are being required in the set of files as well. I just chose bindata as an example.

I have bindata in my Gemfile. When I run bundle show bindata it shows me the path to bindata.

I even put require 'bindata' in my model, but it gave me the same load error.

How do I stop the LoadError?

Any help would greatly be appreciated.

Update 1

When I run bundle show . I get the following:

Gems included by the bundle:
  ...
  * bcrypt (3.1.11)
  * bindata (2.3.4)
  ...

Then in the console, requiring bcrypt works but bindata does not.

irb(main):002:0> require 'bcrypt'
=> true

But bindata does not.

irb(main):003:0> require 'bindata'
LoadError: cannot load such file -- bindata

Update 2

Ok so I know is has to be something with how I am loading my rails environment.

bundle exec irb
irb(main):001:0> require 'bindata'
=> true

Update 3

So I went back a few git commits and keep trying to add the gems and see if they would load in my rails console. I went back far enough were it did. Did not know what was different. However, I also noticed when my spring server was restarted then my gems would load in my rails console.

user2517182
  • 1,241
  • 3
  • 15
  • 37

1 Answers1

0

To require all the files in the lib folder, add config.autoload_paths << Rails.root.join('lib') to your application.rb, this answer can help you: https://stackoverflow.com/a/19650564/3739191

Now,

require 'bindata'

should work :)

Community
  • 1
  • 1
Sébastien P.
  • 526
  • 3
  • 14
  • I am pretty sure it should work, but for some reason (probably something I am still doing wrong) it did not work for me. I added more info to my the question. – user2517182 Nov 17 '16 at 17:44