作業履歴 2025-06-12¶
概要¶
2025-06-12の作業内容をまとめています。このジャーナルでは、開発環境の改善とデバッグ効率化のための設定、およびドキュメントの修正に関する作業を記録しています。
システム構成図¶
作業内容¶
Visual Studio Code開発環境の改善¶
開発効率を向上させるために、Visual Studio Codeの設定を改善しました。特に、デバッグ設定とRuby開発環境の整備に焦点を当てました。
変更点の概要¶
- VSCode用のlaunch.json設定ファイルの更新
- Rubyデバッグ設定の追加
- RSpecテスト実行用のbinstubの追加
技術的詳細¶
Docker環境の改善¶
アプリケーションの実行環境をより本番に近い形で構築するため、Docker環境の設定を更新しました。
変更点の概要¶
- docker-compose.ymlの更新(PostgreSQLの追加)
- 環境変数の整理と統一
- データベース設定の改善
技術的詳細¶
コミット: 8dc2f88¶
メッセージ¶
chore:VSCodeセットアップ
変更されたファイル¶
- M .vscode/launch.json
- M bin/bundle
- A bin/rspec
変更内容¶
commit 8dc2f888f9c43ec5a64b9efda6ce40e6e25165bd
Author: Katuyuki Kakigi <kakimomokuri@gmail.com>
Date: Thu Jun 12 03:35:34 2025 +0000
chore:VSCodeセットアップ
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 097cc98..986756c 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -37,7 +37,7 @@
"name": "RSpec Tests",
"type": "node-terminal",
"request": "launch",
- "command": "bin/bundle exec rspec",
+ "command": "bin/rspec",
"cwd": "${workspaceFolder}",
"env": {
"RAILS_ENV": "test"
@@ -47,11 +47,52 @@
"name": "RSpec Current File",
"type": "node-terminal",
"request": "launch",
- "command": "bin/bundle exec rspec ${file}",
+ "command": "bin/rspec ${file}",
"cwd": "${workspaceFolder}",
"env": {
"RAILS_ENV": "test"
}
+ },
+ {
+ "name": "Debug Rails Server",
+ "type": "rdbg",
+ "request": "launch",
+ "script": "${workspaceFolder}/bin/rails",
+ "args": ["server", "-b", "0.0.0.0", "-p", "3000"],
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "development"
+ },
+ "useBundler": true
+ },
+ {
+ "name": "Debug RSpec Current File",
+ "type": "rdbg",
+ "request": "launch",
+ "script": "${workspaceFolder}/bin/rspec",
+ "args": ["${file}"],
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "test"
+ }
+ },
+ {
+ "name": "Debug RSpec All Tests",
+ "type": "rdbg",
+ "request": "launch",
+ "script": "${workspaceFolder}/bin/rspec",
+ "args": [],
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "test"
+ }
+ },
+ {
+ "name": "Attach to Rails Server",
+ "type": "rdbg",
+ "request": "attach",
+ "rdbgPath": "rdbg",
+ "debugPort": "12345"
}
]
}
diff --git a/bin/bundle b/bin/bundle
index 66e9889..50da5fd 100755
--- a/bin/bundle
+++ b/bin/bundle
@@ -1,3 +1,109 @@
#!/usr/bin/env ruby
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
-load Gem.bin_path('bundler', 'bundle')
+# frozen_string_literal: true
+
+#
+# This file was generated by Bundler.
+#
+# The application 'bundle' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require "rubygems"
+
+m = Module.new do
+ module_function
+
+ def invoked_as_script?
+ File.expand_path($0) == File.expand_path(__FILE__)
+ end
+
+ def env_var_version
+ ENV["BUNDLER_VERSION"]
+ end
+
+ def cli_arg_version
+ return unless invoked_as_script? # don't want to hijack other binstubs
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
+ bundler_version = nil
+ update_index = nil
+ ARGV.each_with_index do |a, i|
+ if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
+ bundler_version = a
+ end
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
+ bundler_version = $1
+ update_index = i
+ end
+ bundler_version
+ end
+
+ def gemfile
+ gemfile = ENV["BUNDLE_GEMFILE"]
+ return gemfile if gemfile && !gemfile.empty?
+
+ File.expand_path("../Gemfile", __dir__)
+ end
+
+ def lockfile
+ lockfile =
+ case File.basename(gemfile)
+ when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
+ else "#{gemfile}.lock"
+ end
+ File.expand_path(lockfile)
+ end
+
+ def lockfile_version
+ return unless File.file?(lockfile)
+ lockfile_contents = File.read(lockfile)
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
+ Regexp.last_match(1)
+ end
+
+ def bundler_requirement
+ @bundler_requirement ||=
+ env_var_version ||
+ cli_arg_version ||
+ bundler_requirement_for(lockfile_version)
+ end
+
+ def bundler_requirement_for(version)
+ return "#{Gem::Requirement.default}.a" unless version
+
+ bundler_gem_version = Gem::Version.new(version)
+
+ bundler_gem_version.approximate_recommendation
+ end
+
+ def load_bundler!
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
+
+ activate_bundler
+ end
+
+ def activate_bundler
+ gem_error = activation_error_handling do
+ gem "bundler", bundler_requirement
+ end
+ return if gem_error.nil?
+ require_error = activation_error_handling do
+ require "bundler/version"
+ end
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
+ exit 42
+ end
+
+ def activation_error_handling
+ yield
+ nil
+ rescue StandardError, LoadError => e
+ e
+ end
+end
+
+m.load_bundler!
+
+if m.invoked_as_script?
+ load Gem.bin_path("bundler", "bundle")
+end
diff --git a/bin/rspec b/bin/rspec
new file mode 100755
index 0000000..cb53ebe
--- /dev/null
+++ b/bin/rspec
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+#
+# This file was generated by Bundler.
+#
+# The application 'rspec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
+
+bundle_binstub = File.expand_path("bundle", __dir__)
+
+if File.file?(bundle_binstub)
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
+ load(bundle_binstub)
+ else
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
+Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
+ end
+end
+
+require "rubygems"
+require "bundler/setup"
+
+load Gem.bin_path("rspec-core", "rspec")
コミット: 7f46019¶
メッセージ¶
chore:VSCodeセットアップ
変更されたファイル¶
- A .vscode/launch.json
変更内容¶
commit 7f4601963232c9223e15b711b9035f70fddb0e29
Author: Katuyuki Kakigi <kakimomokuri@gmail.com>
Date: Thu Jun 12 03:17:43 2025 +0000
chore:VSCodeセットアップ
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..097cc98
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,57 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Rails Server",
+ "type": "node-terminal",
+ "request": "launch",
+ "command": "bin/rails server -b 0.0.0.0 -p 3000",
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "development"
+ }
+ },
+ {
+ "name": "Rails Server (Production)",
+ "type": "node-terminal",
+ "request": "launch",
+ "command": "bin/rails server -b 0.0.0.0 -p 3000 -e production",
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "production",
+ "SECRET_KEY_BASE": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ "PRD_URL": "127.0.0.1"
+ }
+ },
+ {
+ "name": "Rails Console",
+ "type": "node-terminal",
+ "request": "launch",
+ "command": "bin/rails console",
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "development"
+ }
+ },
+ {
+ "name": "RSpec Tests",
+ "type": "node-terminal",
+ "request": "launch",
+ "command": "bin/bundle exec rspec",
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "test"
+ }
+ },
+ {
+ "name": "RSpec Current File",
+ "type": "node-terminal",
+ "request": "launch",
+ "command": "bin/bundle exec rspec ${file}",
+ "cwd": "${workspaceFolder}",
+ "env": {
+ "RAILS_ENV": "test"
+ }
+ }
+ ]
+}
コミット: c6a9e75¶
メッセージ¶
fix:Typo
変更されたファイル¶
- M README.md
変更内容¶
commit c6a9e751f80538b8cc8f79eb3b39236383ddd45b
Author: k2works <kakimomokuri@gmail.com>
Date: Thu Jun 12 10:52:07 2025 +0900
fix:Typo
diff --git a/README.md b/README.md
index 70683ae..acb352f 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ http://127.0.0.1:3000 にアクセスして、アプリケーションが起動
1. [ユーザー認証(2)](#ユーザー認証(2))
1. [ルーティング](#ルーティング)
1. [レコードの表示、新規作成、更新、削除](#レコードの表示、新規作成、更新、削除)
- 1. [Strong Parameters](#Strong Parameters])
+ 1. [Strong Parameters](#Strong Parameters)
1. [アクセス制御](#アクセス制御)
1. [モデル間の関連付け](#モデル間の関連付け)
1. [値の正規化とバリデーション](#値の正規化とバリデーション)
コミット: 76c2989¶
メッセージ¶
Merge remote-tracking branch 'origin/develop' into develop
変更されたファイル¶
変更内容¶
commit 76c2989d29bb52b7d67dbc8e16c5dca1960ae6b6
Merge: d9b605a 2f21c63
Author: k2works <kakimomokuri@gmail.com>
Date: Thu Jun 12 10:50:15 2025 +0900
Merge remote-tracking branch 'origin/develop' into develop
コミット: d9b605a¶
メッセージ¶
fix:Typo
変更されたファイル¶
- M README.md
- D test_customer_message.rb
変更内容¶
commit d9b605ac2e0a40e3ffb9772781208b015e67277d
Author: k2works <kakimomokuri@gmail.com>
Date: Thu Jun 12 10:38:50 2025 +0900
fix:Typo
diff --git a/README.md b/README.md
index 5406c95..70683ae 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ http://127.0.0.1:3000 にアクセスして、アプリケーションが起動
1. [ユーザー認証(2)](#ユーザー認証(2))
1. [ルーティング](#ルーティング)
1. [レコードの表示、新規作成、更新、削除](#レコードの表示、新規作成、更新、削除)
- 1. [String Parameters](#String Parameters])
+ 1. [Strong Parameters](#Strong Parameters])
1. [アクセス制御](#アクセス制御)
1. [モデル間の関連付け](#モデル間の関連付け)
1. [値の正規化とバリデーション](#値の正規化とバリデーション)
@@ -564,8 +564,8 @@ git push heroku master
+ updateアクション
+ destroyアクション
-### String Parameters
-#### String Parameters
+### Strong Parameters
+#### Strong Parameters
+ マスアサインメント脆弱性
+ コントローラのテスト
+ 400 Bad Request
@@ -940,4 +940,4 @@ git push heroku master
+ [Rails Bootstrap Forms](https://github.com/bootstrap-ruby/rails-bootstrap-forms)
+ [Annotate (aka AnnotateModels)](https://github.com/ctran/annotate_models)
+ [MigrationComments](https://github.com/pinnymz/migration_comments)
-+ [i18n_generators](https://github.com/amatsuda/i18n_generators)
\ No newline at end of file
++ [i18n_generators](https://github.com/amatsuda/i18n_generators)
diff --git a/test_customer_message.rb b/test_customer_message.rb
deleted file mode 100644
index f754441..0000000
--- a/test_customer_message.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env ruby
-require_relative 'config/environment'
-
-# Create a customer
-customer = Customer.first || Customer.create!(
- email: 'test@example.com',
- family_name: 'Test',
- given_name: 'User',
- family_name_kana: 'テスト',
- given_name_kana: 'ユーザー',
- password: 'password',
- birthday: Date.new(1980, 1, 1),
- gender: 'male'
-)
-
-# Create a CustomerMessage without staff_member, root, or parent
-message = CustomerMessage.new(
- customer: customer,
- subject: 'Test Subject',
- body: 'Test Body'
-)
-
-puts "Message valid? #{message.valid?}"
-if message.valid?
- message.save!
- puts "Message saved successfully with ID: #{message.id}"
-else
- puts "Message validation errors: #{message.errors.full_messages.join(', ')}"
-end
\ No newline at end of file
コミット: 2f21c63¶
メッセージ¶
chore:不要なコード削除
変更されたファイル¶
- D test_customer_message.rb
変更内容¶
commit 2f21c631f45c00e5e73a50fb1b2197f8c3ac46b5
Author: k2works <kakimomokuri@gmail.com>
Date: Thu Jun 12 10:38:50 2025 +0900
chore:不要なコード削除
diff --git a/test_customer_message.rb b/test_customer_message.rb
deleted file mode 100644
index f754441..0000000
--- a/test_customer_message.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env ruby
-require_relative 'config/environment'
-
-# Create a customer
-customer = Customer.first || Customer.create!(
- email: 'test@example.com',
- family_name: 'Test',
- given_name: 'User',
- family_name_kana: 'テスト',
- given_name_kana: 'ユーザー',
- password: 'password',
- birthday: Date.new(1980, 1, 1),
- gender: 'male'
-)
-
-# Create a CustomerMessage without staff_member, root, or parent
-message = CustomerMessage.new(
- customer: customer,
- subject: 'Test Subject',
- body: 'Test Body'
-)
-
-puts "Message valid? #{message.valid?}"
-if message.valid?
- message.save!
- puts "Message saved successfully with ID: #{message.id}"
-else
- puts "Message validation errors: #{message.errors.full_messages.join(', ')}"
-end
\ No newline at end of file
コミット: 3d3d40f¶
メッセージ¶
chore:docker-compose更新
変更されたファイル¶
- M .gitignore
- M config/database.yml
- M docker-compose.yml
変更内容¶
commit 3d3d40fb03a78e498d8787bdd0a5c53916845d9b
Author: k2works <kakimomokuri@gmail.com>
Date: Thu Jun 12 10:15:21 2025 +0900
chore:docker-compose更新
diff --git a/.gitignore b/.gitignore
index 40045d9..ee66fe4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,6 +88,7 @@ config/initializers/secret_token.rb
## Environment normalization:
/.bundle
/vendor/bundle
+.gem_rbs_collection
# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset
@@ -108,4 +109,4 @@ bower.json
public/assets/
.idea/
-*.iml
\ No newline at end of file
+*.iml
diff --git a/config/database.yml b/config/database.yml
index 1b2c8a0..c42297f 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -15,10 +15,10 @@ development:
encoding: utf8
collation: utf8_general_ci
pool: 5
- username: root
- password: password
- host: <%= ENV.fetch("MYSQL_HOST", "127.0.0.1") %>
- database: baukis-kai_development
+ username: <%= ENV.fetch("DB_USER", "root") %>
+ password: <%= ENV.fetch("DB_PASSWORD", "password") %>
+ host: <%= ENV.fetch("DB_HOST", "127.0.0.1") %>
+ database: <%= ENV.fetch("DB_DATABASE", "bauki-kai_development") %>
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@@ -28,10 +28,10 @@ test:
encoding: utf8
collation: utf8_general_ci
pool: 5
- username: root
- password: password
- host: <%= ENV.fetch("MYSQL_HOST", "127.0.0.1") %>
- database: baukis-kai_test
+ username: <%= ENV.fetch("DB_USER", "root") %>
+ password: <%= ENV.fetch("DB_PASSWORD", "password") %>
+ host: <%= ENV.fetch("DB_HOST", "127.0.0.1") %>
+ database: "app_test"
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
@@ -58,8 +58,8 @@ production:
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
- username: postgres
- password: password
- host: 127.0.0.1
- database: baukis-kai_production
+ username: <%= ENV.fetch("DB_USER", "postgres") %>
+ password: <%= ENV.fetch("DB_PASSWORD", "password") %>
+ host: <%= ENV.fetch("DB_HOST", "127.0.0.1") %>
+ database: <%= ENV.fetch("DB_DATABASE", "bauki-kai_production") %>
diff --git a/docker-compose.yml b/docker-compose.yml
index d9c992c..101dc00 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,48 +4,68 @@ services:
context: .
dockerfile: Dockerfile-app
depends_on:
- - db
+ - db_prd
environment:
- MYSQL_HOST: db
- MYSQL_PORT: 3306
- MYSQL_USER: user
- MYSQL_PASSWORD: pass
- MYSQL_DATABASE: app_development
+ RAILS_ENV: production
+ SECRET_KEY_BASE: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ PRD_URL: 127.0.0.1
+ DB_HOST: db_prd
+ DB_PORT: 5432
+ DB_USER: postgres
+ DB_PASSWORD: password
+ DB_DATABASE: app_production
ports:
- - "3000:3000"
+ - "3001:3000"
working_dir: /app
volumes:
- ./:/app
- db:
+
+ db_dev:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: user
- MYSQL_PASSWORD: pass
+ MYSQL_PASSWORD: password
+ MYSQL_DATABASE: app_development
ports:
- 3306:3306
volumes:
- mysql-db:/var/lib/mysql
+ db_prd:
+ image: postgres:17
+ environment:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: password
+ POSTGRES_INITDB_ARGS: "--encoding=UTF-8"
+ POSTGRES_DB: app_production
+ user: postgres
+ ports:
+ - "5432:5432"
+ volumes:
+ - postgresql-db:/var/lib/postgresql
+
console:
build:
context: .
dockerfile: Dockerfile-console
environment:
- MYSQL_HOST: db
- MYSQL_PORT: 3306
- MYSQL_USER: user
- MYSQL_PASSWORD: pass
- MYSQL_DATABASE: app_development
+ DB_HOST: db_dev
+ DB_PORT: 3306
+ DB_USER: root
+ DB_PASSWORD: password
+ DB_DATABASE: app_development
volumes:
- ./:/srv
working_dir: /srv
depends_on:
- - db
+ - db_dev
stdin_open: true
ports:
- - "3333:3000"
+ - "3000:3000"
volumes:
mysql-db:
- driver: local
\ No newline at end of file
+ driver: local
+ postgresql-db:
+ driver: local