毎日学習記録 9/2 Railsでよく調べる箇所

Share on:

概要

今日はいくつか新しくインストールする際に、よくつまづくことや設定などで気が付いたことのメモ

railsについて

環境

  • Ruby 2.7
  • Ruby on Rails 6

mysql2をbundle install時にエラーが出る

opensslなどインストールしていて、以下を忘れたためだった。

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

既存DBのテーブルを利用したい

class Modelname < ApplicationRecord
  self.table_name = "tablename"
end

docker buildした際にワーニングが出る

docker buildした際に以下のようなワーニングが出る。

$ docker-compose build application

Building application
Step 1/9 : FROM ruby:2.7.1-buster
 ---> 958d3491c09a
Step 2/9 : RUN apt update -qq    && apt install -y build-essential                          libpq-dev                          nodejs                          npm
 ---> Running in a43d0855ef37

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

2 packages can be upgraded. Run 'apt list --upgradable' to see them.

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

どうやら下のような使い分けが必要のよう

  • apt :コンソールなどインタラクティブシェルで利用する
  • apt-get: docker buildなど処理で利用する場合はこっちを利用する

参考

Qiita:【Rails】MySQL2がbundle installできない時の対応方法

blog: aptとapt-getの違い