Connecting to a database
So far, we’ve created a Person
model and the migrations needed for the structure of our database. Now we are ready to connect to our database. But wait, we’ve already connected to a database! As previously stated, if we were able to run our migration successfully, it means that we did indeed connect to the SQLite database. Now let’s take a look at how Rails is configured to do this. Let’s examine our Gemfile, and in doing so, we’ll see the following line:
… # Use sqlite3 as the database for Active Record gem 'sqlite3' …
The preceding line installs the sqlite3
gem that allows Rails to communicate with a SQLite database. But wait, there’s more. If we open the app/config/database.yml
file, we will also see some of the database settings for our project:
… default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>...