Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Brand new rails app, can't generate scaffold

Although I'm not an expert, I've developed a few rails apps in-house to use for some relatively small/medium sized projects and haven't had any issues as similar to this one before.

I'm just simply trying to create a new app, followed by a scaffold, and I'm getting an error about the sqlite3 gem. Check this out (example of my issue):

[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)

I saw that another thread (replace_gem: Error loading the 'sqlite3' Active Record adapter - while creating model) that suggested adding gem 'sqlite3', '~> 1.3', '>= 1.3.6' to the gemfile, but this does not do anything for me.

[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)

What's going on here? Not sure what else to do here.

like image 666
LewlSauce Avatar asked Feb 06 '19 22:02

LewlSauce


People also ask

What is the difference between scaffolding and models in Ruby on rails?

The best way to explain the difference between scaffold and models is to use the command: generate models. Scaffolding in Ruby on Rails refers to the auto-generation of a set of a model, views and a controller usually used for a single database table.

How to create a bookstore app in rails?

Let’s start by creating a Rails app, say, an online bookstore. In your terminal, run the following command: This creates an app with the name bookstore. Change directory to our bookstore. When starting to write code for our app, we would usually have to generate models and controllers using rails generate (or rails g ).

How do I auto-generate a scaffold for a story table?

You can auto-generate a ready to use controller, model, and views with a full CRUD (Create, Read, Update, Delete) web interface for the Story table using the following command: $rails generate scaffold. The best way to explain the difference between scaffold and models is to use the command: generate models.

How do I create a rails 7 app?

If you want to create a Rails 7 app, you’re going to need some software installed and configured. Step one, you need an up-to-date (2.7.0 or newer) version of Ruby installed. You can check what version, if any, you have already installed by running, ruby -v.


1 Answers

The error states that it can't find a version of sqlite3 ~> 1.3.6 so that is what your Gemfile should require:

gem 'sqlite3', '~> 1.3.6'

The more lenient definition of gem 'sqlite3', '~> 1.3', '>= 1.3.6' which will also allow 1.4 is only valid for the master branch of rails.

Edit

The 5-2-stable branch actually now also allows using sqlite 1.4 but the currently released 5.2.2 gem does not.

Update 2019-03-18

Now that rails 5.2.2.1 has been released, the correct and also easiest fix is to bump rails to that version, as it will restrict sqlite3 to 1.3.6:

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

Given the security fixes in that version, this should be done anyway.

like image 92
ulferts Avatar answered Oct 09 '22 05:10

ulferts