无法加载这样的文件 - 在Heroku上的Twitter,sinatra应用程序

时间:2016-10-20 01:44:37

标签: ruby heroku twitter sinatra

我已经能够使用sinatra在本地运行我的应用程序,但是当我将它推送到heroku时,我不断收到此错误:

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

我授权自己在初始化文件中使用twitter gem。

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 /初始化/ 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

即使是rake任务,我仍然在本地获得以下错误:

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)

Rake文件

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

LIB /任务/ scheduler.rake

require './../bot'

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

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

end

如何在我的本地运行调度程序,以便我可以将它添加到heroku?

1 个答案:

答案 0 :(得分:1)

您似乎正在投放:

require 'Twitter'

注意大写T。如果你改为运行它是否有效:

require 'twitter'

看起来您的本地计算机正在运行OS X,它通常使用不区分大小写的HFS +文件系统。

Heroku在Linux系统上运行,Linux系统通常使用区分大小写的文件系统。