全新的Rails应用程序,无法生成支架

时间:2019-02-06 22:49:34

标签: ruby-on-rails

尽管我不是专家,但我内部已经开发了一些Rails应用程序,可用于一些相对较小/中型的项目,并且以前没有类似的问题。

我只是尝试创建一个新应用,然后创建一个脚手架,而我得到了关于sqlite3 gem的错误。检查一下(我的问题的示例):

[user:ubuntu:~/Documents/rails_apps]$ rails new goku
[user:ubuntu:~/Documents/rails_apps]$ cd goku
[user:ubuntu:~/Documents/rails_apps/goku]$ rails g scaffold FindingName name:text
Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile. (LoadError)

我看到另一个线程(replace_gem: Error loading the 'sqlite3' Active Record adapter - while creating model)建议将gem 'sqlite3', '~> 1.3', '>= 1.3.6'添加到gemfile,但这对我没有任何作用。

[user:ubuntu:~/Documents/rails_apps/goku]$ bundle install                                                                                                                               4:47PM/02.06
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 1.5.3
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.2
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.1
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.0.4
Using actionview 5.2.2
Using rack 2.0.6
Using rack-test 1.1.0
Using actionpack 5.2.2
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.7.0
Using actioncable 5.2.2
Using globalid 0.4.2
Using activejob 5.2.2
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailer 5.2.2
Using activemodel 5.2.2
Using arel 9.0.0
Using activerecord 5.2.2
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.2
Using public_suffix 3.0.3
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.11.0
Using bindex 0.5.0
Using msgpack 1.2.6
Using bootsnap 1.3.2
Using bundler 1.16.2
Using byebug 10.0.2
Using regexp_parser 1.3.0
Using xpath 3.2.0
Using capybara 3.13.2
Using ffi 1.10.0
Using childprocess 0.9.0
Using chromedriver-helper 2.1.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 0.20.3
Using railties 5.2.2
Using coffee-rails 4.2.2
Using multi_json 1.13.1
Using jbuilder 2.8.0
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.0
Using ruby_dep 1.5.0
Using listen 3.1.5
Using puma 3.12.0
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.2
Using rubyzip 1.2.2
Using sass-listen 4.0.0
Using sass 3.7.3
Using tilt 2.0.9
Using sass-rails 5.0.7
Using selenium-webdriver 3.141.0
Using spring 2.0.2
Using spring-watcher-listen 2.0.1
Using sqlite3 1.4.0
Using turbolinks-source 5.2.0
Using turbolinks 5.2.0
Using uglifier 4.1.20
Using web-console 3.7.0
Bundle complete! 18 Gemfile dependencies, 79 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
[user:ubuntu:~/Documents/rails_apps/goku]$ rails g scaffold FindingName name:text                                                                                                       4:47PM/02.06
      invoke  active_record
Traceback (most recent call last):
    70: from bin/rails:4:in `<main>'
    69: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    68: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    67: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    66: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    65: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    64: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    63: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    62: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    61: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
    60: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke'
    59: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform'
    58: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
    57: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    56: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    55: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/generate/generate_command.rb:26:in `perform'
    54: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/generators.rb:276:in `invoke'
    53: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
    52: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
    51: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
    50: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
    49: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
    48: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
    47: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    46: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    45: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/group.rb:134:in `_invoke_from_option_orm'
    44: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/group.rb:266:in `_invoke_for_class_method'
    43: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/shell.rb:68:in `with_padding'
    42: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/group.rb:277:in `block in _invoke_for_class_method'
    41: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:115:in `invoke'
    40: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
    39: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
    38: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
    37: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
    36: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
    35: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    34: from /home/user/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    33: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/rails/generators/active_record/model/model_generator.rb:22:in `create_migration_file'
    32: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/generators/named_base.rb:92:in `table_name'
    31: from /home/user/.rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/generators/named_base.rb:201:in `pluralize_table_names?'
    30: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    29: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    28: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    27: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    26: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    25: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    24: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    23: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    22: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/base.rb:27:in `<main>'
    21: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
    20: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    19: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
    18: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    17: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
    16: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
    15: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
    14: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
    13: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/railtie.rb:136:in `block (2 levels) in <class:Railtie>'
    12: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:60:in `establish_connection'
    11: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:952:in `establish_connection'
    10: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/connection_adapters/connection_specification.rb:191:in `spec'
     9: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
     8: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
     7: from /home/user/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
     6: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
     5: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
     4: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
     3: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
     2: from /home/user/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
     1: from /home/user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:12:in `<main>'
/home/user/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile. (LoadError)

这是怎么回事?不知道这里还有什么。

2 个答案:

答案 0 :(得分:8)

该错误表明它找不到sqlite3 ~> 1.3.6的版本,因此您的Gemfile应该要求:

gem 'sqlite3', '~> 1.3.6'

更宽松的gem 'sqlite3', '~> 1.3', '>= 1.3.6'定义也将允许1.4仅对rails的master分支有效。

修改

5-2-stable branch实际上现在还允许使用sqlite 1.4,但当前发布的5.2.2 gem不允许。

更新2019-03-18

现在,rails 5.2.2.1 has been released的正确且也是最简单的解决方法是将rails扩展到该版本,因为它将sqlite3限制为1.3.6

# In Gemfile
gem 'rails', '~> 5.2.2.1'

鉴于该版本中的安全修复程序,无论如何都应这样做。

答案 1 :(得分:0)

我认为问题是您已经在系统中安装了sqlite 1.4。您能否先尝试将其删除,然后再尝试bundle install

如果这样不起作用,请尝试以下命令:

bundle clean --force
bundle install