Domanda

I'm trying to run a Sinatra application with the most basic app.rb:

require 'sinatra/activerecord/rake'
require 'bundler/setup'
Bundler.require(:default)

require_relative './config'
require_relative './models/star'
require_relative './models/planet'
require_relative './models/moon'
require_relative './models/astronaut'

get '/' do 
  erb :index
end

After using Bundle and creating Gemfile.lock I'm keep getting this error:

You have already activated activesupport 4.0.2, but your Gemfile requires activesupport 3.2.16. Using bundle exec may solve this. (Gem::LoadError)

My Rakefile is:

source 'https://rubygems.org'

gem 'sinatra'
gem 'sinatra-reloader'
gem 'sinatra-activerecord'
gem 'activerecord', '~> 3.2.13'
gem 'rake'
gem 'pg'
gem 'pry'

I'll be grateful for any suggestions.

È stato utile?

Soluzione

You have both ActiveRecord 4.0.2 and 3.2.13 installed on your system. The first line of your app requires sinatra/activerecord/rake which in turn requires activerecord, without specifying which version. This activates and loads 4.0.2 – the latest version.

In the next line you try to set up Bundler. Bundler now tries to activate version 3.2.13 of ActiveRecord as specified in your Gemfile, but can’t since a version is already activated, so you get an error.

To fix, simply make sure you call require 'bundler/setup' first, before you require any other files. This will ensure any files you require will be compatible with your Gemfile.

Alternatively you could remove the call to require bundler/setup and make sure you always start your app using bundle exec.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top