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
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.
My output when running my ruby cli file includes lines like:
D, [2018-11-17T15:33:29.481676 #45237] DEBUG -- : Patient Load (0.6ms) SELECT "patients".* FROM "patients"
I copied things from other sample projects for my environment, Gemfile, and Rakefile, and obviously something is set up to output this. How do I turn it off?
My gemfile:
source "https://rubygems.org"
gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-nav'
gem 'activesupport'
gem 'nokogiri'
gem "activerecord"
gem "sinatra-activerecord"
gem "sinatra"
gem "sqlite3"
gem "rake"
gem "database_cleaner"
group :test do
gem 'poltergeist'
gem 'capybara'
gem 'rspec'
end
My rakefile:
# ENV['SINATRA_ENV'] ||= "development"
$LOADED_FEATURES << 'fake/active_support/core_ext/hash'
require_relative './config/environment'
require 'sinatra/activerecord/rake'
task :console do
Pry.start
end
My environment:
ENV['SINATRA_ENV'] ||= "development"
$LOADED_FEATURES << 'fake/active_support/core_ext/hash'
require 'bundler/setup'
Bundler.require
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: "db/#{ENV['SINATRA_ENV']}.sqlite"
)
require 'active_record'
require 'rake'
Dir[File.join(File.dirname(__FILE__), "../app/models", "*.rb")].each {|f| require f}
Dir[File.join(File.dirname(__FILE__), "../lib", "*.rb")].each {|f| require f}
Active record logs sql output in development mode by default. To disable it,
try adding this line before the section after it like so
ActiveRecord::Base.logger = nil
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: "db/#{ENV['SINATRA_ENV']}.sqlite"
)
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.
What am I missing? I've included slim in my Gemfile & 'required' it.
config.ru:
require './sinatra.rb'
run Sinatra::Application
Gemfile:
source 'https://rubygems.org'
gem 'rack'
gem 'sinatra'
gem 'slim'
sinatra.rb:
require 'sinatra'
require 'slim'
get '/' do
slim :index
end
I am trying to rake db:migrate. I cloned a repository and tried to rake db:migrate, but get this error :
rake aborted!
Unable to determine name from existing gemspec. Use :name => 'gemname' in #inst
ll_tasks to manually set it. C:/Users/Dila/Documents/emo_project/Rakefile:6:in `<top (required)>'
In my Rakefile line 6, I have this :
require "bundler/gem_tasks"
This is what I got, when I trace it :
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:30:i
n `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:14:i
n `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:14:i
n `install_tasks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_tasks.rb:2:in
`<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `block in require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:236:in `load_dependency'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `require'
C:/Users/Dila/Documents/emo_project/Rakefile:6:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `l
oad'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `l
oad_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `
raw_load_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `b
lock in load_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `
standard_exception_handling'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `l
oad_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `b
lock in run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `
standard_exception_handling'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `r
un'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>
'
C:/Ruby193/bin/rake:23:in `load'
C:/Ruby193/bin/rake:23:in `<main>'
I have no idea what is went wrong, because yesterday I was working in my office and everything was ok. I just wanna try to clone the repository in my laptop, but it doesn't work.
my gemfile :
source 'https://rubygems.org'
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
group :production do
gem 'pg', '0.12.2'
end
gem 'magic_encoding'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'activeadmin'
gem "bcrypt-ruby", :require => "bcrypt"
# to copy to clipboard
gem 'zeroclipboard-rails'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#gem 'therubyracer'
gem 'uglifier', '>= 1.0.4'
gem 'sass-rails', '~> 3.2'
gem 'bootstrap-sass', '~> 2.3.1.0'
gem 'closure-compiler'
end
gem 'jquery-rails'
I see in your gemfile that you set postgresql as your production database, however you also set sqlite to run on production, test, and development.
group :production do
gem 'pg', '0.12.2'
end
# Skip some lines to here
gem 'sqlite3'
I would make sure your database is uniform across the test, development, and production servers. I would remove sqlite3 and simply have
group :production do
gem 'pg', '0.12.2'
end
replaced with
gem 'pg', '0.12.2'
That way, postgresql will run on all platforms. Or if your database.yml is connected to sqlite, then get rid of postgresql and keep the sqlite gem in your gemfile.