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?
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.
Related
I'm trying to deploy a simple Ruby app to Heroku. I keep getting this error in the release logs, which look like this:
rake aborted!
NameError: uninitialized constant Dotenv
/app/config/environment.rb:5:in `<top (required)>'
/app/Rakefile:3:in `require_relative'
/app/Rakefile:3:in `<top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:63:in `load'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:63:in `kernel_load'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:28:in `run'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:474:in `exec'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:30:in `dispatch'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:24:in `start'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/exe/bundle:49:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/exe/bundle:37:in `<top (required)>'
/app/vendor/bundle/bin/bundle:113:in `load'
/app/vendor/bundle/bin/bundle:113:in `<main>'
(See full trace by running task with --trace)
I've googled this a bunch and tried every suggestion, but I can't seem to fix it. For reference, here's my Gemfile:
source 'http://rubygems.org'
gem 'sinatra'
gem 'activerecord', "< 6", :require => 'active_record'
gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
gem 'rake'
gem 'require_all'
gem 'thin'
gem 'bcrypt'
gem 'sinatra-flash'
gem 'rails_12factor'
gem 'foreman'
group :development, :test do
gem 'sqlite3', '<1.4'
gem 'shotgun'
gem 'tux'
gem 'pry'
gem 'session_secret_generator'
gem 'dotenv'
end
group :production do
gem 'pg', '0.20'
end
group :test do
gem 'rspec'
gem 'capybara'
gem 'rack-test'
gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'
end
and here's my config/environment.rb:
ENV['SINATRA_ENV'] ||= "development"
require 'bundler/setup'
Bundler.require(:default, ENV['SINATRA_ENV'])
Dotenv.load if ENV['SINATRA_ENV'] == "development"
set :database_file, "./database.yml"
require './app/controllers/application_controller'
require_all 'app'
Thanks!
Maybe you are missing: require 'dotenv' before trying Dotenv.load?
Problems
Note that your Gemfile places dotenv into your :development and :test groups. It is not available in your default or :production groups, so you are unlikely to be getting your gem loaded via Bundler.require as currently configured.
Suggested Solutions
My suggestions include:
ensure you're using APP_ENV to set your Sinatra environment, not something custom like SINATRA_ENV, which may or may not doing what you think on Heroku
use Heroku's config-vars rather than dotenv in production
note that Heroku probably defaults to excluding :development, :test, and :ci groups when running bundle install, but you can configure this behavior via environment variables
move dotenv to your default group (if you really need it everywhere)
if you don't move dotenv into the default group, you need to modify your Bundler.require to add the correct group containing the dotenv gem into the list of groups to require (provided Bundler has installed that group)
You may have other issues as well, but these are the ones that jumped out at me from the code and errors you provided.
Im working on w10 64bits
app.rb
require 'rubygems'
require 'sinatra'
require "sinatra/activerecord"
require 'sqlite3/sqlite3_native'
class App < Sinatra::Base
#configuraciones
set :root, File.dirname(__FILE__)
set :session_secret, 'super secret'
set :public_folder, File.dirname(__FILE__) + '/public'
set :layout, 'views/layouts'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'data.db'
)
enable :sessions
#before all requests
before do
headers['server'] = 'Ruby, Ubuntu'
end
end
rakefile.rb
require "sinatra/activerecord/rake"
require 'sqlite3/sqlite3_native'
require 'sinatra'
require './app'
gemfile
source "https://rubygems.org"
gem "sinatra"
gem "json"
gem 'sinatra-activerecord', '~> 2.0', '>= 2.0.9'
gem 'rake'
gem 'sqlite3'
so when i try to do db:migrate i cant do it, sqlite3 version 1.3.13
execute command
bundle exec rake db:migrate
rake aborted!
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
so i dont know what is exactly the problem need help
UPDATE
I change in rakefile.rb for only require 'sqlite3'
but know i get other error
rake aborted!
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
Caused by:
LoadError: cannot load such file -- sqlite3/2.5/sqlite3_native
C:/ruby/sinatra/Rakefile.rb:2:in `<top (required)>'
Try removing sqlite3_native from your rakefile.rb and just require sqlite3
I have a series of selenium/capybara specs that I'm running via rspec in a ruby project. Thus far I have been running them exclusively on a windows machine without issue. Now I am trying to migrate to a Linux machine and I'm running into issues all over the place.
In my spec_helper.rb which every one of my test files requires, I start off with this bit below. Yet when I run my tests on the Linux server, I'm getting a dozens of uninitialized constant errors. Basically the first class the code hits is being declared uninitialized despite having been initialized elsewhere.
# frozen-string-literal: true
require 'rspec'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
require 'capybara/dsl'
require 'selenium-webdriver'
require 'site_prism'
Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each do |helper|
require helper
end
Dir[File.dirname(__FILE__) + '/page_objects/mixins/*.rb'].each do |page_object|
require page_object
end
Dir[File.dirname(__FILE__) + '/page_objects/sections/*.rb'].each do |page_object|
require page_object
end
Dir[File.dirname(__FILE__) + '/page_objects/*/*.rb'].each do |page_object|
require page_object
end
one such stacktrace:
An error occurred while loading ./demo_spec.rb.
Failure/Error: iframe :export_modal, Pages::ExportModal, :xpath, '//*[#id="qPopupWindow"]/iframe'
NameError:
uninitialized constant Pages::ExportModal
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/page_objects/pages/entity_gl_periods.rb:18:in `<class:EntityGlPeriods>'
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/page_objects/pages/entity_gl_periods.rb:2:in `<module:Pages>'
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/page_objects/pages/entity_gl_periods.rb:1:in `<top (required)>'
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/spec_helper.rb:22:in `block in <top (required)>'
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/spec_helper.rb:21:in `each'
# /dr01/bamboo/xml-data/build-dir/DEVSYS-RSM2FT-JOB1/spec/spec_helper.rb:21:in `<top (required)>'
# ./demo_spec.rb:1:in `<top (required)>'
No examples found.
Stack trace tells you error is on line 21 of spec_helper
The error somewhere in here:
Dir[File.dirname(__FILE__) + '/page_objects/*/*.rb'].each do |page_object|
require page_object
end
If you're able to get into the server console, see what this actually returns and compare to your windows environment.
Dir[File.dirname(__FILE__) + '/page_objects/*/*.rb']
It seems like the load order of your requires are not firing correctly. Is it possible there are permission errors on the directories you're trying to read/load from?
getting error on running cmd in windows Please help me what to do: here is rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for
example lib/tasks/capistrano.rake, and they will automatically be available to
Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
and here is the cmd window
c:\Fedena>rake db:create --trace
(in c:/Fedena)
rake aborted!
c:/Fedena/Rakefile:3: syntax error, unexpected kAND
...lib/tasks/capistrano.rake, and they will automatically be av...
^
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
C:/Ruby187/bin/rake:23:in `load'
C:/Ruby187/bin/rake:23
Shouldn't this part be commented out?
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for
#example lib/tasks/capistrano.rake, and they will automatically be available to
#Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
Looks like it's not commented out and ruby is trying to run it as code
My installation is successful. Below is my rake file content:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
Copy and paste the above content in your rake file and try again
I have a Rakefile that requires some Bundler tasks
Rakefile:
require "bundler/gem_tasks"
require "rake/testtask"
.
.
.
And a minitest file that loads the Rakefile so I can test my tasks:
load File.expand_path("../../Rakefile", __FILE__)
require 'minitest/autorun'
require 'rake'
class RakeTest < Minitest::Test
def test_rake_just_works
assert_output("Running some_namespace:some_task...\n") do
Rake::Task["some_namespace:some_task"].invoke
end
end
end
The problem is Sublime doesn't like the require "bundler/gem_tasks" and gives the following error:
/Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:30:in `initialize': Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it. (RuntimeError)
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:14:in `new'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:14:in `install_tasks'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_tasks.rb:6:in `<top (required)>'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/Rakefile:1:in `<top (required)>'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb:1:in `load'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb:1:in `<main>'
[Finished in 0.5s with exit code 1]
[shell_cmd: /Users/max/.rbenv/shims/ruby "/Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb"]
[dir: /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
There is no error if I run ruby test/rake_test.rb from the command-line (leaving the require statement as is):
➜ some_gem master ✗ ruby test/rake_test.rb
Run options: --seed 45743
# Running:
.
Finished in 0.002035s, 491.4005 runs/s, 491.4005 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
Sublime does work if I remove the require statement, but then I lose all my Bundler rake tasks.
I found an issue that references this problem in the context of using the Bundler tasks for multiple gems. Seems different than my use-case but I tried the solution anyways and it doesn't work, and gives the same error:
Rakefile:
require "bundler/gem_tasks"
Bundler::GemHelper.install_tasks :name => "some_gem"
require "rake/testtask"
I think it might have to do with the path for Sublimes build system. I tried using my rbenv ruby shim but it also didn't work:
{
"shell_cmd": "/Users/max/.rbenv/shims/ruby \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}