toy
toy

Reputation: 12141

`require': no such file to load -- lib/book (LoadError) on Heroku, Sinatra

I have created a simple app and this is my folder structure

And this is my config.ru


require './server'
run Sinatra::Application

When I deploy to heroku I got this error `require': no such file to load -- lib/book (LoadError). However, on my local machine it works fine.

I'm not sure what to include in config.ru I tried require './lib/book' as well, but it didn't work.

Thanks a lot.

Upvotes: 0

Views: 1384

Answers (1)

rkallensee
rkallensee

Reputation: 2024

You could try to add the /lib directory to your $LOAD_PATH by adding something like this to your server.rb:

configure do
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
  Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| 
    require File.basename(lib, '.*') 
  }
end

This will add the /lib directory to your $LOAD_PATH and require all *.rb files in it.

Upvotes: 1

Related Questions