ブログアプリケーションを作成する : 小林研 Rails Tips (46)

はじめに

Rails Tips の 46 回目です。昨日、PostgreSQL の設定が終わったので、rails new でブログアプリケーションを作成してみます。Rails ガイドでは 3.2 節です。

Rails をはじめよう - Railsガイド

3.2 ブログアプリケーションを作成する

おととい、Rails のオプションを確認しました。ここで指定したオプションをつけて blog を作成してみます。-B オプションをつけているので、bundle install は実行されていません。

$ rails new hkob_blog -d postgresql -a propshaft -T --main -B
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init from "."
Initialized empty Git repository in /Users/hkob/Library/CloudStorage/Dropbox/rails/hkob_blog/.git/
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  Dockerfile
      create  .dockerignore
      create  bin/docker-entrypoint
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/new_framework_defaults_7_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  app/assets/config/manifest.js
      remove  app/assets/config
      remove  app/assets/stylesheets/application.css
      create  app/assets/stylesheets/application.css
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_7_1.rb

Gemfile に取り急ぎ直近で使うものだけ入れておきます。haml-rails は運用でも利用しますが、それ以外のものは development, test 環境でインストールするものです。

gem "haml-rails"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri windows ]

  gem "rspec-rails"
  gem "guard-rspec"
  gem "yard"
  gem "yard-activerecord"
  gem "rubocop-performance"
  gem "rubocop-rails"
  gem "rubocop-rspec"
  gem "haml-lint"
end

あるマシンで bundle install したらエラーになったのですが、昨日環境を整備したマシンで再度実行したところ正しく動作しました。エラーになったマシンも Ruby を再インストールしたら無事に成功しました。gem が壊れていたのかもしれません。

bundle install
Fetching https://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Fetching useragent 0.16.10
Fetching pg 1.5.4
Fetching reline 0.4.2
Fetching bindex 0.8.1
Fetching puma 6.4.2
Fetching msgpack 1.7.2
Fetching net-imap 0.4.9.1
Fetching net-smtp 0.4.0.1
Installing useragent 0.16.10
Fetching jbuilder 2.11.5
Installing pg 1.5.4 with native extensions
Installing bindex 0.8.1 with native extensions
Installing reline 0.4.2
Fetching irb 1.11.1
Installing puma 6.4.2 with native extensions
Installing msgpack 1.7.2 with native extensions
Installing net-imap 0.4.9.1
Installing net-smtp 0.4.0.1
Installing jbuilder 2.11.5
Installing irb 1.11.1
Fetching importmap-rails 2.0.1
Fetching propshaft 0.8.0
Fetching stimulus-rails 1.3.3
Fetching turbo-rails 1.5.0
Installing importmap-rails 2.0.1
Fetching web-console 4.2.1
Installing propshaft 0.8.0
Installing stimulus-rails 1.3.3
Installing turbo-rails 1.5.0
Installing web-console 4.2.1
Fetching bootsnap 1.17.1
Installing bootsnap 1.17.1 with native extensions
Bundle complete! 12 Gemfile dependencies, 71 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

おわりに

とりあえずマシンのトラブルで時間がかかってしまって、ここまでになってしまいました。明日はもう少し設定を進めることにします。