sahil sahil - 1 month ago 8
Ruby Question

cannot load such file -- Twitter, sinatra app on Heroku

I have been able to run my app locally using sinatra, but the moment I push it to heroku, I keep getting this error:

/app/lib/initializers/twitter.rb:1:in `require': cannot load such file -- Twitter


I authorize myself using the twitter gem in a initializer file.

init.rb



APP_ROOT = File.dirname(__FILE__)
require 'sinatra'
require 'json'
require File.join(APP_ROOT,"lib","bot")
require './lib/bot'

get '/' do
File.read(File.join( APP_ROOT, 'index.html'))
end


lib/initializers/twitter.rb



require 'Twitter'

$client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
config.consumer_secret = ENV["CONSUMER_SECRET"]
config.access_token = ENV["ACCESS_TOKEN"]
config.access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
end


Gemfile



ruby '2.3.1'
source 'https://rubygems.org'
gem 'rack'
gem 'twitter'
gem 'sinatra'
gem "sinatra-activerecord"
gem 'thin'
gem 'json'


config.ru



require './lib/initializers/secrets'
require './lib/initializers/twitter'
require './init'
run Sinatra::Application


Even for rake task I keep getting the below error in my local:

LoadError: cannot load such file -- active_record/railties/databases.rake
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/sinatra-activerecord-2.0.11/lib/sinatra/activerecord/rake.rb:1:in `load'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/sinatra-activerecord-2.0.11/lib/sinatra/activerecord/rake.rb:1:in `<top (required)>'
/Users/sahil/Documents/work/practice/twitter_bot/Rakefile:2:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
LoadError: cannot load such file -- sinatra/activerecord/rake
/Users/sahil/Documents/work/practice/twitter_bot/Rakefile:2:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)


Rakefile



require "./lib/bot"
require "sinatra/activerecord/rake"
Dir.glob('lib/tasks/*.rake').each { |r| load r}


lib/tasks/scheduler.rake



require './../bot'

desc "This task is called by the Heroku scheduler add-on"

task :fav_tweets => :environment do
bot = Bot.new

end


How can I run a scheduler in my local first so that I can add the same to heroku?

Answer

You appear to be running:

require 'Twitter'

Note the capital T. Does it work if you run instead:

require 'twitter'

It looks like your local machine is running OS X, which typically uses a case-insensitive HFS+ filesystem.

Heroku runs on Linux systems, which typically use case-sensitive filesystems.

Comments