UNDO for 25's procon
本番環境へのデプロイ方法については、以下のドキュメントを参照してください:
ドキュメント | 説明 | 対象者 |
---|---|---|
デプロイガイド | Kamalを使用した詳細なデプロイ手順 | 初めてデプロイする人 |
クイックリファレンス | よく使うコマンドと操作のリファレンス | 日常的にデプロイする人 |
デプロイチェックリスト | デプロイ前後の確認事項 | 全員 |
トラブルシューティング | 問題発生時の対処法 | 問題が発生した時 |
設定例 | deploy.ymlの詳細な設定例 | 設定を変更する人 |
初回デプロイの場合:
# 1. 依存関係のインストール
bundle install
# 2. deploy.ymlを編集(サーバーIP、ドメイン名等)
vi config/deploy.yml
# 3. 環境変数を設定
export KAMAL_REGISTRY_PASSWORD="your-password"
# 4. デプロイ実行
bin/kamal setup
更新のデプロイの場合:
bin/kamal deploy
詳細はデプロイガイドを参照してください。
各ユーザーは個別の設定を持ち、BOD上限値、位置情報、Bluetooth UUIDなどを管理できます。
コントローラーまたはビューで以下のように使用します:
# コントローラー・ビューどちらでも使用可能
current_user_setting.bod_upper_limit # BOD上限値(デフォルト: 5000)
current_user_setting.location # 位置情報
current_user_setting.average_estimated_value # 平均推定値
current_user_setting.bt_service_uuid # Bluetooth Service UUID(読み取り専用)
current_user_setting.bt_characteristic_uuid # Bluetooth Characteristic UUID(読み取り専用)
# 設定オブジェクトを取得
user = User.find(1)
setting = user.setting
# ショートカットメソッドを使用
user.bod_upper_limit # 5000
user.location # nil または設定値
user.bt_service_uuid # Bluetooth UUID
setting = current_user_setting
setting.bod_upper_limit = 6000
setting.location = "Tokyo"
setting.average_estimated_value = 4500
setting = current_user_setting
setting.update_settings(
bod_upper_limit: 7000,
location: "Osaka",
average_estimated_value: 5000
)
class UserSettingsController < ApplicationController
before_action :authenticate_user!
def update
if current_user_setting.update_settings(user_setting_params)
redirect_to root_path, notice: '設定を更新しました'
else
render :edit, status: :unprocessable_entity
end
end
private
def user_setting_params
params.require(:user_setting).permit(:bod_upper_limit, :location, :average_estimated_value)
end
end
ユーザー作成時に自動的に以下のデフォルト値が設定されます:
設定項目 | デフォルト値 | 変更可能 |
---|---|---|
bod_upper_limit |
5000 |
✅ |
location |
nil |
✅ |
average_estimated_value |
nil |
✅ |
bt_service_uuid |
"0696b0a8-b883-4d89-a87c-1f5d5e78d0e9" |
❌ |
bt_characteristic_uuid |
"3d8828a9-e983-4235-a25a-25b741e81893" |
❌ |
Bluetooth UUIDは読み取り専用で、update_settings
メソッドでも変更できません:
# これらは常に読み取り専用
current_user_setting.bt_service_uuid # 変更不可
current_user_setting.bt_characteristic_uuid # 変更不可
# update_settingsでも無視される
setting.update_settings(bt_service_uuid: "new-value") # 無視される
<%# app/views/dashboard/index.html.erb %>
<div class="user-settings">
<p>BOD上限値: <%= current_user_setting.bod_upper_limit %></p>
<p>位置情報: <%= current_user_setting.location || '未設定' %></p>
<% if current_user_setting.average_estimated_value %>
<p>平均推定値: <%= current_user_setting.average_estimated_value %></p>
<% end %>
</div>
シンボルまたは文字列で設定値を取得できます:
setting = current_user_setting
setting.get(:bod_upper_limit) # 5000
setting.get("location") # nil または設定値
setting.get(:average_estimated_value) # nil または設定値
- 自動作成: ユーザー作成時に設定は自動的に作成されます(規定値が読み込まれるのはユーザー初回ログイン時です)
- nil安全:
current_user_setting
は未ログイン時にnil
を返します - 永続化: 個別のセッターメソッド(
bod_upper_limit=
など)は自動的に保存されますsetting.bod_upper_limit = 6000 # 自動的に保存される # または一括更新 setting.update_settings(bod_upper_limit: 6000) # 複数の設定を一度に更新
# test/models/user_setting_test.rb
test "can update individual settings" do
setting = @user.setting
setting.bod_upper_limit = 6000
assert_equal 6000, setting.bod_upper_limit
end
開発サーバーを立ち上げるには、以下のコマンドを実行します:
$ bin/dev
本番環境での動作確認を行う場合は、以下のコマンドを使用します:
$ RAILS_ENV=production bin/rails assets:precompile
$ bin/prod
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
# 認証成功
else
# 認証失敗
end
./bin/importmap pin <package-name>
でもダウンロードはできるが、型定義ファイルやソースマップが含まれないため、npm
タスクを使用。
使い方は以下を参照されたい。
$ rake npm:help
- うどん店舗情報のファイルたちを
db/seeds/stores/**/*
に配置してね - そのあとこれを叩いてね
更新時もこれでOK
$ rails db:seed
$ RAILS_ENV=test bin/rails assets:precompile
$ rails db:test:prepare
rails c
undo(dev)> ActiveRecord::Base.connection.tables
=> ["stores", "reviews", "measurements", "sessions", "user_settings", "schema_migrations", "ar_internal_metadata", "users"]
has_many :sessions
- セッション管理has_one :user_setting
- ユーザー設定(1対1)has_many :written_reviews
- 書いたレビュー
belongs_to :user
- 所属するユーザー- JSON形式で柔軟な設定を保存
- デフォルト値を自動設定
belongs_to :store
- レビュー対象の店舗belongs_to :reviewer
(User) - レビューを書いたユーザー
- ユーザーの測定記録を管理
has_many :reviews
- 店舗に対するレビュー- うどん店の情報を管理