Can't start Mongoid with Sinatra - ruby

I'm trying to get started with Mongoid in a Sinatra app, but it looks like I'm running into dependency issues. If it helps, I'm on a Macbook Pro using RVM and running Ruby 1.9.3.
Here are the errors I'm getting after running $ ruby config.ru:
/Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/specification.rb:1637:in `raise_if_conflicts': Unable to activate mongoid-3.0.23, because activemodel-4.0.0 conflicts with activemodel (~> 3.1) (Gem::LoadError)
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/specification.rb:746:in `activate'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems.rb:212:in `rescue in try_activate'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems.rb:209:in `try_activate'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/duncanmalashock/Penumbra/penumbra.rb:4:in `<top (required)>'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from config.ru:2:in `<main>'
Can anyone help?
Here are the files involved:
mongoid.yml:
development:
sessions:
default:
database: mongoid
hosts:
- localhost:27017
config.ru:
require 'sinatra'
require './penumbra'
run Sinatra::Application
Gemfile:
source :rubygems
source :rubyforge
# Thin Server
gem 'thin'
# Sinatra
gem 'sinatra'
gem 'sinatra-contrib', :require => 'sinatra/multi_route'
gem 'sinatra-partial', :require => 'sinatra/partial'
gem 'sinatra-reloader'
# MongoDB
gem "mongoid"
# Shopify
gem 'shopify_api'
penumbra.rb:
require 'sinatra'
require 'shopify_api'
require 'mongo'
require 'mongoid'
require 'json'
require "sinatra/reloader" if development?
Mongoid.load!("./mongoid.yml", :production)
def isactivepage(link_name)
if (link_name == #page_name)
return ' activelink'
else return ''
end
end
get '/' do
#page_name = "Home"
erb :"pages/index"
end
get '/about' do
#page_name = "About"
erb :"pages/about"
end
After running $ bundle exec rackup:
/Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/mongoid-1.0.6/lib/mongoid.rb:68:in `method_missing': undefined method `load!' for #<Mongoid::Config:0x007fc0838cb1d0> (NoMethodError)
from /Users/duncanmalashock/Penumbra/penumbra.rb:9:in `<top (required)>'
from /Users/duncanmalashock/Penumbra/config.ru:2:in `require'
from /Users/duncanmalashock/Penumbra/config.ru:2:in `block in <main>'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/duncanmalashock/Penumbra/config.ru:in `new'
from /Users/duncanmalashock/Penumbra/config.ru:in `<main>'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/bin/rackup:23:in `load'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/bin/rackup:23:in `<main>'

You have a Gemfile, but you’re not starting your app using Bundler, and that’s why you have the conflict.
The current version of shopify_api (3.0.3) has a dependency on activemodel via activeresource with the version requirements set to >=3.0.0. On your system you have Rails 4 installed, so activemodel 4.0 is loaded.
The current version of mongoid also has a dependency on activemodel, but this time the version requirement is ~> 3.2.
These two version requirements are not compatible, so you get the error activemodel-4.0.0 conflicts with activemodel (~> 3.1).
To fix it, simply use Bundler to start your app. You say you are running with $ ruby config.ru but this isn’t the correct way to use a config.ru (you would get errors later even if you fixed your dependency issues). You should use rackup. In this case you should run:
$ bundle exec rackup

Related

Could not load 'active_record/connection_adapters/redshift_adapter'

I ran into the error when I tried to run SQL through ruby script. Can someone help me figure out what could be the cause? I already looked for some similar posts but couldn't find the right solution yet.
/Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require': Could not load 'active_record/connection_adapters/redshift_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/pg-0.17.1/lib/pg.rb:4:in `<top (required)>'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord4-redshift-adapter-0.2.1/lib/active_record/connection_adapters/redshift_adapter.rb:17:in `<top (required)>'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /Users/User/Desktop/github/tracker/app/workers/appsflyer_importer_worker_aggregate.rb:100:in `fetch_data'
from /Users/User/Desktop/github/tracker/app/workers/appsflyer_importer_worker_aggregate.rb:120:in `perform'
from -:30:in `<main>'
Here is my settings:
Gemfile
ruby '2.4.3'
gem 'activerecord4-redshift-adapter', '~> 0.2'
gem 'pg'
Ruby version
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
Gem list
activerecord (4.2.10, 4.2.8)
activerecord4-redshift-adapter (0.2.1)
pg (1.0.0, 0.17.1)
Script
require 'active_record'
conn = {
adapter: 'redshift',
database: '#database',
host: '#host',
port: 5439,
username: '#username',
password: '#password'
}
ActiveRecord::Base.establish_connection(conn)
sql = 'select count(*) from table'
ActiveRecord::Base.connection.execute(sql)
You're using the pg gem version 1.0.0 and it is not compatible with the version of active_record and activerecord4-redshift-adapter that you're using:
The PGconn, PGresult, and PGError constants are deprecated, and will be removed as of version 1.0.
This can be seen in the history of the pg gem.
The activerecord4-redshift-adapter uses both the PGconn and PGError constants:
def connection_active?
#connection.status == PGconn::CONNECTION_OK
rescue PGError
false
end
Although I was unable to exactly duplicate the error message that you saw, by modifying the Gemfile to use an older version of the pg gem I was able to get farther along:
gem 'pg', '~> 0.21'
My exact steps were:
create the Gemfile
create a file test.rb containing your Ruby code
run bundle install
run bundle exec ruby test.rb
This produces the following error:
/Users/test/.rvm/gems/ruby-2.4.3/gems/activerecord4-redshift-adapter-0.2.1/lib/active_record/connection_adapters/redshift_adapter.rb:568:in `initialize': could not translate host name "#host" to address: nodename nor servname provided, or not known (PG::ConnectionBad)
This is almost certainly in the right direction for the problem you're having, and should put you on the path to accomplishing your goal.

rake aborted! uninitialized constant Logging::Logger::INFO - Namespace collision with WinRM and Albacore

Ruby/Rake NOOB and have inherited set of C# projects that use ruby & rake for build/deploy.
The build quit working last week because of an old gem. In the process of updating all gems to recent versions, I've run into this uninitialized constant problem.
There were no code changes involved and I tried adding "require 'logging'" to setup.rb.
I've been working under the assumption that the problem is in our rake files, but after pounding on this for hours I'm not so sure. I haven't found anyplace in our code that uses the constant.
Any suggestions or help appreciated.
Windows Server 2008 with Ruby 2.0.0.
gem list output:
*** LOCAL GEMS ***
akami (1.2.1)
albacore (0.3.6)
aws-sdk (1.38.0)
bigdecimal (1.2.0)
builder (3.2.2)
bundler (1.6.0)
ffi (1.9.3 x86-mingw32)
gssapi (1.0.3)
gyoku (1.1.1)
httpclient (2.3.4.1)
httpi (0.9.7)
io-console (0.4.2)
json (1.8.1, 1.7.7)
little-plugger (1.1.3)
logging (1.8.2)
mini_portile (0.5.3)
minitest (4.3.2)
multi_json (1.9.2)
nokogiri (1.6.1 x86-mingw32)
nori (1.1.5)
psych (2.0.0)
rack (1.5.2)
rake (0.9.6)
rdoc (4.0.0)
rubyntlm (0.1.1)
rubyzip (0.9.9)
savon (0.9.5)
test-unit (2.0.0.0)
uuidtools (2.1.4)
wasabi (1.0.0)
win32-service (0.8.4)
winrm (1.1.3)
and the rake output:
rake aborted!
uninitialized constant Logging::Logger::INFO
C:/Ruby200/lib/ruby/2.0.0/rake/ext/module.rb:36:in `const_missing'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/albacore-0.3.6/lib/albacore/support/logging.rb:7:in `initialize'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/albacore-0.3.6/lib/albacore/support/failure.rb:7:in `initialize'
C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:13:in `initialize'
C:/Ruby200/lib/ruby/2.0.0/psych/nodes/node.rb:35:in `new'
C:/Ruby200/lib/ruby/2.0.0/psych/nodes/node.rb:35:in `to_ruby'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:130:in `load'
C:/build-dir/MV-MB-JOB1/deploy/setup.rb:5:in `block in <top (required)>'
C:/build-dir/MV-MB-JOB1/deploy/setup.rb:5:in `open'
C:/build-dir/MV-MB-JOB1/deploy/setup.rb:5:in `<top (required)>'
C:/build-dir/MV-MB-JOB1/deploy/rakefile.rb:15:in `require_relative'
C:/build-dir/MV-MB-JOB1/deploy/rakefile.rb:15:in `<top (required)>'
C:/Ruby200/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load'
C:/Ruby200/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load_rakefile'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:604:in `raw_load_rakefile'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:89:in `block in load_rakefile'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:88:in `load_rakefile'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:72:in `block in run'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
C:/Ruby200/lib/ruby/2.0.0/rake/application.rb:70:in `run'
C:/Ruby200/bin/rake:37:in `<main>'
setup.rb:
require "yaml"
#environment = ENV["environment"] || "development"
#version = ENV["version"] || "none"
#configuration = File.open(File.join("environment", #environment, "global_config.yml"), "rb") {|f| YAML::load(f)}
#configuration.merge!({:environment => #environment,
:version => #version,
:repository_path => ENV["repository_path"]})
There seems to be a namespace collision between the WinRM and Albacore gems AND WinRM uses the 'logging' gem, Albacore uses 'logger'. Both define Logger.
Using the following command:
rake -f myTest.rb --trace
This works:
require "winrm"`
require "albacore"
task :default do
end
This does not:
require "albacore"
require "winrm"
task :default do
end
Albacore implements lib\albacore\support\logging.rb:
require 'logger'
module Logging
attr_accessor :logger, :current_log_device
def initialize
create_logger(STDOUT, Logger::INFO)
super()
end
def log_device=(logdev)
level = #logger.level
create_logger(logdev, level)
end
.
.
.
end
WinRm does the following in winrm.rb:
require 'date'
require 'kconv' if(RUBY_VERSION.start_with? '1.9') # bug in rubyntlm with ruby 1.9.x
require 'logging'
module WinRM
Logging.logger.root.level = :info
Logging.logger.root.appenders = Logging.appenders.stdout
end
require 'winrm/helpers/iso8601_duration'
require 'winrm/soap_provider'
Not suggesting this as an appropriate fix, but wrapping the Albacore Logging module in another module, and updating Albacore references to Logging (Albacore::Logging), solves the problem.
Altered lib\albacore\support\logging.rb:
module Albacore
module Logging
.
.
.
end
end
Update:
I opened an Albacore issue. 2.0.0.rc.10, released today, includes a fix for the name collision issue. However, migrating from pre-2.0 Albacore to 2.0.0 is not pain-free because some of the task types have been generalized. Albacore nunit has been replaced by task_runner. Albacore msbuild is now simply 'build'.
The conflict can also be solved by moving the require down in to the task that needs it, as such:
require "albacore"
task :default do
...
end
task :some_winrm_task do
require "winrm"
...
end

undefined method `desc' for Sinatra::Application:Class

This is the error I get when I run any rake command: undefined method 'desc' for Sinatra::Application:Class
# app.rb
require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/contrib'
get '/' do
puts "Hello World"
end
# config.ru
require "./app"
run Sinatra::Application
# Rakefile
require './app'
require 'sinatra/activerecord/rake'
# Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
gem 'activerecord', '~> 4.0.2'
gem 'sinatra', '~> 1.4.4'
gem 'sinatra-activerecord', '~> 1.2.3'
gem 'sinatra-contrib', '~> 1.4.2'
Full trace:
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:269:in `method_missing'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-activerecord-1.2.3/lib/sinatra/activerecord/tasks.rake:4:in `block in <top (required)>'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:126:in `class_eval'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:126:in `block in new'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:118:in `initialize'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:118:in `new'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:118:in `new'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-contrib-1.4.2/lib/sinatra/namespace.rb:142:in `namespace'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1972:in `block (2 levels) in delegate'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-activerecord-1.2.3/lib/sinatra/activerecord/tasks.rake:3:in `<top (required)>'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-activerecord-1.2.3/lib/sinatra/activerecord/rake.rb:77:in `<top (required)>'
/Users/j/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/j/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/backports-3.3.5/lib/backports/tools.rb:328:in `require_with_backports'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/j/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/Users/j/Desktop/app/Rakefile:2:in `<top (required)>'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `load'
/Users/j/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `<main>'
/Users/j/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/Users/j/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
Found an easiest solution:
Juste add the require:false attribute to sinatra contrib in your gemfile:
gem "sinatra-contrib",require: false
Found this here:
http://aaronlerch.github.io/blog/sinatra-bundler-and-the-global-namespace/
The Sinatra namespace extension from Sinatra contrib is interfering with Rake’s own namespace support. They both define a namespace method, and the Sinatra contrib version is being called (incorrectly) from the Sinatra-ActiveRecord Rake tasks.
If you’re not using the namespaces from Sinatra-contrib, then the easiest solution would be to only require those extensions that you need; e.g. change
require 'sinatra/contrib'
to
require 'sinatra/whatever'
require 'sinatra/anotherextension'
If you are using Sinatra namespaces then I think you may be able to get round this by moving to a modular style app. Change your app.rb to something like
require 'sinatra/base' # note this has changed from just 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/contrib'
class MyApp < Sinatra::Base
register Sinatra::Contrib
get '/' do
"Hello World"
end
# other routes etc. as needed
end
Then in your config.ru you need run MyApp rather then run Sinatra::Application (of course you can – and should – give your class a better name). This avoids the collision of the two namespace methods, since the Sinatra version is only available in your application class, not the top level.

Rake task not working with postgresql and sinatra-activerecord

I was trying to setup facebook app locally, using ruby and sinatra, in Kubuntu 12.04.
I have included following gems in my gemfile. I have postgresql installed in my system and I am able to run the postgresql command line and run basic commands as createdb, create table etc.
gem "sinatra"
gem "koala"
gem "json", "1.5.5"
gem "httparty"
gem "thin"
gem "rack", "1.3.10"
gem "pg"
gem "activerecord"
gem "sinatra-activerecord"
And in my app.rb file added these files,
require "rubygems"
require "sinatra"
require "sinatra/activerecord"
require "koala"
require "./config/environment" #database configuration
Running
rake -T
in my terminal gives me the following error.
rake aborted!
(<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
/var/lib/gems/1.9.1/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord.rb:39:in `database_file='
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1033:in `set'
/var/lib/gems/1.9.1/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord.rb:50:in `registered'
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1317:in `block in register'
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1315:in `each'
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1315:in `register'
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1648:in `register'
/var/lib/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1688:in `register'
/var/lib/gems/1.9.1/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord.rb:76:in `<module:Sinatra>'
/var/lib/gems/1.9.1/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord.rb:6:in `<top (required)>'
/home/nitin/facebook_app/guarded-gorge-3234/app.rb:3:in `<top (required)>'
/home/nitin/facebook_app/guarded-gorge-3234/Rakefile:1:in `<top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `raw_load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `block in load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Could any one please help. Thank you.
As #iain mentioned, this is due to a parse error in your config/database.yml file.
Check that it is valid syntax, and replace any tabs with spaces.

Redmine Installation with activerecord-mysql-adapter

I'm working on a CentOS 6.3 Linux server with the Ruby version: 1.8.7 and the Gem version: 1.8.25
I'm trying to run the command: ruby script/rails server webrick -e production
It spits out this error:
=> Booting WEBrick
=> Rails 3.2.8 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib64/ruby/gems/1.8/gems/bundler-1.2.3/lib/bundler/rubygems_integration.rb:157:in `gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (can't activate mysql (~> 2.8.1), already activated mysql-2.9.0. Make sure all dependencies are added to Gemfile.) (LoadError)
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql_adapter.rb:5
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/base.rb:721
from /var/www/redmine/lib/plugins/acts_as_activity_provider/init.rb:2
from /var/www/redmine/config/initializers/00-core_plugins.rb:12
from /var/www/redmine/config/initializers/00-core_plugins.rb:2:in `each'
from /var/www/redmine/config/initializers/00-core_plugins.rb:2
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:588
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:587:in `each'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:587
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `run_initializers'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `send'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/redmine/config/environment.rb:14
from /var/www/redmine/config.ru:4:in `require'
from /var/www/redmine/config.ru:4
from /usr/lib64/ruby/gems/1.8/gems/rack-1.4.0/lib/rack/builder.rb:51:in `instance_eval'
from /usr/lib64/ruby/gems/1.8/gems/rack-1.4.0/lib/rack/builder.rb:51:in `initialize'
from /var/www/redmine/config.ru:1:in `new'
from /var/www/redmine/config.ru:1
This is my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.2.8'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem "rake", "0.8.7"
gem "rack", "1.4.0"
gem "rubytree", "0.5.2", :require => "tree"
gem "RedCloth", "~>4.2.3", :require => "redcloth" # for CodeRay
gem "mysql", "2.9.0"
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
gem "rack-openid"
end
# Optional gem for exporting the gantt to a PNG file, not supported with jruby
platforms :mri, :mingw do
group :rmagick do
# RMagick 2 supports ruby 1.9
# RMagick 1 would be fine for ruby 1.8 but Bundler does not support
# different requirements for the same gem on different platforms
gem "rmagick", ">= 2.0.0"
end
end
# Database gems
platforms :mri, :mingw do
group :postgresql do
gem "pg", ">= 0.11.0"
end
group :sqlite do
gem "sqlite3"
end
end
platforms :mri_18, :mingw_18 do
group :mysql do
gem "mysql", "2.9.0"
end
end
platforms :mri_19, :mingw_19 do
group :mysql do
gem "mysql2", "~> 0.3.11"
end
end
platforms :jruby do
gem "jruby-openssl"
group :mysql do
gem "activerecord-jdbcmysql-adapter"
end
group :postgresql do
gem "activerecord-jdbcpostgresql-adapter"
end
group :sqlite do
gem "activerecord-jdbcsqlite3-adapter"
end
end
group :development do
gem "rdoc", ">= 2.4.2"
gem "yard"
end
group :test do
gem "shoulda", "~> 2.11"
# Shoulda does not work nice on Ruby 1.9.3 and seems to need test-unit explicitely.
gem "test-unit", :platforms => [:mri_19]
gem "mocha", "0.12.3"
end
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(local_gemfile)
end
# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end
I've installed activerecord-mysql-adapter -- it had no errors...
I've tried to change the Gemfile to match the error it's spitting out, the (~> 2.8.1) version but that did not work either...
Any help would really be appreciated...
UPDATE!!
I uninstalled MySQL 2.9.0 and installed MySQL 2.8.1 and changed my Gemfile to reflect the proper version, but now I'm getting this error:
=> Booting WEBrick
=> Rails 3.2.8 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query': Mysql::Error: Table 'redmine.users' doesn't exist: SHOW FULL FIELDS FROM `users` (ActiveRecord::StatementInvalid)
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql_adapter.rb:324:in `execute_and_free'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:426:in `columns'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/schema_cache.rb:12:in `initialize'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `call'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `default'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `[]'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `columns'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:237:in `columns_hash'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/inheritance.rb:19:in `descends_from_active_record?'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/inheritance.rb:25:in `finder_needs_type_condition?'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/base.rb:455:in `relation'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/scoping/named.rb:37:in `scoped'
from /usr/lib64/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/querying.rb:9:in `order'
from /var/www/redmine/app/models/group.rb:32
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:359:in `require_or_load'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:313:in `depend_on'
from /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:225:in `require_dependency'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:439:in `eager_load!'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:438:in `each'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:438:in `eager_load!'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:436:in `each'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:436:in `eager_load!'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/application/finisher.rb:53
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `run_initializers'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `send'
from /usr/lib64/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/redmine/config/environment.rb:14
from /var/www/redmine/config.ru:4:in `require'
from /var/www/redmine/config.ru:4
from /usr/lib64/ruby/gems/1.8/gems/rack-1.4.0/lib/rack/builder.rb:51:in `instance_eval'
from /usr/lib64/ruby/gems/1.8/gems/rack-1.4.0/lib/rack/builder.rb:51:in `initialize'
from /var/www/redmine/config.ru:1:in `new'
from /var/www/redmine/config.ru:1
EDIT: I figured it out... I needed to run the command: RAILS_ENV=production bundle exec rake db:migrate
DOH!
Try
bundle exec ruby script/rails server webrick -e production
Also, why are you using script/rails? This should work:
bundle exec rails server webrick -e production
HTH

Resources