Error with data_mapper and json gems

1

Gem :: Conflict Error: Unable to activate dm-serializer-1.2.2, because json-2.0.2 conflicts with json (~ > 1.6)

gem list --local


*** LOCAL GEMS ***

actioncable (5.1.0)
actionmailer (5.1.0)
actionpack (5.1.0)
actionview (5.1.0)
activejob (5.1.0)
activemodel (5.1.0)
activerecord (5.1.0)
activesupport (5.1.0)
addressable (2.5.1)
arel (8.0.0)
bcrypt (3.1.11)
bcrypt-ruby (3.1.5)
bigdecimal (default: 1.3.0)
builder (3.2.3)
bundler (1.14.6)
concurrent-ruby (1.0.5)
daemons (1.2.4)
data_mapper (1.2.0)
data_objects (0.10.17)
datamapper-dm-core (0.10.1)
did_you_mean (1.1.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.1)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.2)
dm-sqlite-adapter (1.2.0)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.2)
dm-validations (1.2.0)
do_sqlite3 (0.10.17)
erubi (1.6.0)
eventmachine (1.2.3)
extlib (0.9.16)
fastercsv (1.5.5)
globalid (0.4.0)
i18n (0.8.1)
io-console (default: 0.4.6)
json (default: 2.0.2)
json_pure (2.1.0, 1.8.6)
loofah (2.0.3)
mail (2.6.5)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
multi_json (1.12.1)
mustermann (1.0.0)
net-telnet (0.1.1)
nio4r (2.0.0)
nokogiri (1.7.2)
openssl (default: 2.0.2)
power_assert (0.4.1)
psych (default: 2.2.2)
public_suffix (2.0.5)
rack (2.0.2, 1.6.5)
rack-protection (2.0.0, 1.5.3)
rack-test (0.6.3)
rails (5.1.0)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.0.3)
railties (5.1.0)
rake (12.0.0)
rdoc (default: 5.0.0)
shotgun (0.9.2)
sinatra (2.0.0, 1.4.8)
slim (3.0.7)
sprockets (3.7.1)
sprockets-rails (3.2.0)
stringex (1.5.1)
temple (0.7.7)
test-unit (3.2.3)
thin (1.7.0)
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.7)
tzinfo (1.2.3)
uuidtools (2.1.5)
websocket-driver (0.6.5)
websocket-extensions (0.1.2)
xmlrpc (0.2.1)

How can I solve this problem?

I use Ubuntu 16.04 LTS.

Previously, install data_mapper and return synatra error with the same feature, update with gem sinatra update and work on another project if data_mapper. When I wanted to use it it returned the current error with JSON.

    
asked by Nicoo1991 23.05.2017 в 02:28
source

1 answer

1

Apparently version 2.0.0 of Sinatra does not work correctly with DataMapper, you can see the problem report here .

Therefore, you can try using version 1.4.8 instead of 2.0.0; to do it you have two options:

1. Use bundler .

Bundler allows you to manage the gems (with specific versions) that you will use through a Gemfile (more information here ), in which you can specify the versions that you will use in your project; in your case you would use version 1.4.8 of Sinatra:

gem "sinatra", "~> 1.4.8"

Once you generate your Gemfile and execute the bundle install command, the Gemfile.lock file will be generated, which contains the information of all the gems used in your project along with their dependencies.

2. Delete version 2.0.0.

By removing this version of Sinatra, you will only have version 1.4.8 available, so you will not have the problem described; to do it execute the following command:

$ gem uninstall sinatra --version 2.0.0

I highly recommend trying with the first option (i.e. use Bundler ), since it will give you the freedom to install different versions of gems for different projects without affecting each other.

How to use Bundler with a Gemfile file

Suppose your application is called MiApp , it is found in mi_app/app.rb and has the following code:

require 'sinatra'

class MiApp < Sinatra::Base
  get "/" do
    "Hola mundo!"
  end
end
  • Create a file Gemfile , in the root directory of your application, with the following content:

    source "https://rubygems.org"
    
    gem 'sinatra',           '1.4.8'
    gem 'data_mapper',       '1.2.0'
    gem 'dm-sqlite-adapter', '1.2.0'
    gem 'json',              '~>1.6'
    gem 'thin',              '1.7.0'
    gem 'slim',              '3.0.8'
    gem 'shotgun',           '0.9.2'
    
  • Create a file configu.ru , also in the root directory of your application, with the following content:

    require 'rubygems'
    require 'bundler'
    
    Bundler.require
    
    require './app'
    run MiApp
    

    Where app refers to the name of your file (i.e. app.rb ) and MiApp to the name of your class within that file.

  • Execute shotgun using bundle exec (to use the appropriate version of rake ):

    $ bundle exec shotgun
    
  • With this configuration you guarantee that your application uses the gems and versions indicated in Gemfile , regardless of the versions you have installed on your system.

        
    answered by 23.05.2017 / 17:43
    source