user1049097
user1049097

Reputation: 1901

Rails not recognizing lib files?

I have a lib/redirect_follower.rb file

Where I use the file, I include it with require 'RedirectFollower'

But rails is playing hard ball with this error:

no such file to load -- RedirectFollower

Any clues? Been banging my head over this for hours. Have tried auto loading all libs using application.rb but that didn't work either.

Upvotes: 4

Views: 545

Answers (2)

Marek Příhoda
Marek Příhoda

Reputation: 11198

In config/application.rb: add this:

config.autoload_paths << "#{config.root}/lib"

With this setting, your modules (i.e. files under lib/) will be automatically required so you don't have to require them anywhere (actually, you should never require them because that would have an negative effect on un/loading files by Rails).

Upvotes: 2

user229044
user229044

Reputation: 239541

require is for including a file, not a class.

You need to require "redirect_follower", ie, the actual filename, not the class name. You may also need to add lib to your include path, or require "lib/redirect_follower".

Upvotes: 3

Related Questions