Error Loading Active Record Gem with Sinatra App Using Rvm

Error loading Active Record gem with sinatra app using RVM

As far as I can tell require 'activerecord' has been deprecated. Try using

require 'active_record'

instead.

Tux with Sinatra cannot load

Your error is this:

cannot load such file -- ./app (LoadError)

That error is saying that tux cannot find a file called app.rb in the current directory. tux is looking for that file because your config.ru says this:

config.ru
require "./app"
run Sinatra::Application

See how it mentions a file called "./app"? Well, the "tutorial" doesn't show you the screenshot for that file until after it shows you the screenshot for tux. So create the app.rb file, then run tux.

Also change your Gemfile from this:

source :rubygems

to this:

source 'https://rubygems.org'

(When you did .../blog$ bundle install Bundler should have given you a warning about that.)

Another error you will encounter further on:

In tux, it says to do this:

>> p = new_record?

That should be:

>> p.new_record?

rackup cannot load activerecord

Even though the gem is called activerecord, the class is called ActiveRecord, which converts to active_record in snake case:

require 'active_record'

cannot load such file -- Twitter, sinatra app on 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.

Sinatra Activerecord: private method `load' called for Psych:Module (NoMethodError)

Setting

set :database, {adapter: 'postgresql', database: '_your_database_name_'}

instead of

set :database_file, "../../config/database.yml"

helps, but I'm still not sure where the bug came from.

rake db:migrate not working when using ActiveRecord with Sinatra

I was having the same problem, and I believe I found the answer to your second question, why you had to revert to an older version of Active Record (5.2 instead of 6.0).

If you look at the sinatra-activerecord repo, it looks like they've deprecated ActiveRecord::Base.establish_connection() and replaced it with set :database{}.

So, if you change your code:

ActiveRecord::Base.establish_connection(:adapter =>'sqlite3', :database=>'wiki.db')

to

set :database, {:adapter =>'sqlite3', :database=>'wiki.db'}

Your code should work without having to use an older version of Active Record. At least that worked for me.



Related Topics



Leave a reply



Submit