0

I'm facing a problem in a project using Rails 5.2 without ActiveRecord.

I've runned the command rails new project --skip-active-record and it's ok, but when I run a command to generate a model I get this error:

.rvm/gems/ruby-2.5.1/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:404:in `block (2 levels) in replace_gem': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (Gem::LoadError)

I didn't understand why it ask about sqlite 3 in active record if I disabled it and I search over internet and don't find anyone talking about.

What is wrong?

Thanks

sidneivl
  • 242
  • 3
  • 12

4 Answers4

1

If you don't want to use ActiveRecord then there's no need to generate a model using rails g. You can just go to the app/models directory in your application and create a plain ruby class to work with it as a model.

Swaps
  • 1,450
  • 24
  • 31
  • So, If I want connect an external API using RestClient gem I need create my models manually, right? Because to create a model Rails by default necessity a database dependent? – sidneivl May 08 '18 at 19:14
  • I haven't used the `RestClient` gem on my own, but yeah you can always create a model on your own. Afterall its just a class. If its inheriting `AR::Base` it'll have a functionality to work with DB table as well. – Swaps May 09 '18 at 05:36
1

The command

rails g model MODEL

will generate model, migration and fixtures. And this is related to ORM. So rails will look at database configuration. There you would have mentioned the ORM client as

adapter: sqlite3

You need to install sqlite3 gem for this. Add

gem 'sqlite3'

to your Gemfile

If you want to add just model alone create file inside app/models folder. But whats the point in doing this? Rails will look for the table name respect to the model's class name and throw an error

0

I assume you don't have an ORM. If that is the case then running rails generate model shouldn't do anything, it shouldn't even install sqlite by default. Try updating your sqlite gem

Kenji
  • 1
  • 2
0

The $ bin/rails generate model ... command actually creates a migration and an ActiveRecord model that's why you get the database-related error. See Model Generators.

Hoa
  • 3,179
  • 1
  • 25
  • 33