sinatra-activerecord: LoadError: cannot load such file -- active_record/railties/databases.rake
When I require 'sinatra/activerecord/rake'
in my Rakefile I get this error
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 29 (12 by maintainers)
Did you forget to use
bundle exec
?You have to run
rake -T
withbundle exec
đYou need to run âbundle exec rake db:migrateâ, then it should work.
Rake is a task runner, and imagine tasks as simple Ruby scripts that do something. The â-Tâ flag tells Rake just to print the list of available tasks. See documentation for ActiveRecord on better explanation of these Rake tasks.
YaaaaâŚgithubâŚI no useâŚmaybe have this comments, some people have same problem. They just try to change this order. 1ărequire â./appâ 2ărequire âsinatra/activerecord/rakeâ
maybe ok, no error message. Thank you for janko-m
just upgrade to 2.0.14 , problem solved.
In Ruby there is a thing called âload pathâ (you can inspect it with
puts $LOAD_PATH
). This is a list of paths where yourequire
from. Think of it as shellâsPATH
variable, where shell searches for executables that you want to run.When you do
require "active_record"
, it actually requires a file like this:So, on itâs own, Ruby just requires the latest version of ActiveRecord, which may not be the version you want.
What Bundler does is âlocksâ a specific version of ActiveRecord (specified in your Gemfile) by adding the correct version of the gem to the
$LOAD_PATH
, so thenrequire
will require that version of the gem.Now, you may notice that the
$LOAD_PATH
doesnât contain any gems when not using Bundler, yet you can still require gems without Bundler. Thatâs becauserequire
in Ruby is a bit smarter, it knows where are your gems. So, if it isnât able to require something from the load path, it will search in gem directories.In this specific case Iâm using
load
instead ofrequire
(because I have to require a .rake file, which I canât do withrequire
). Andload
is a bit stupider, in the sense that if it doesnât find the file in the$LOAD_PATH
, it wonât search through gems. Thatâs why you need Bundler, to add ActiveRecord to the load path so thatload
can find it.