Posts

Rails 8 rails new コマンドのオプションについて

  • POST
Rails 8 rails new コマンドのオプションについてまとめたものを備忘録として残しておく 環境 ruby: 3.4.2 rails: 8.0.2 mode: API mode 全オプション rails new -h で確認 Usage: rails new APP_PATH [options] Options: [--skip-namespace] # Skip namespace (affects only isolated engines) # Default: false [--skip-collision-check] # Skip collision check # Default: false -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/kazuki_kawazoe/.rbenv/versions/3.4.2/bin/ruby -n, [--name=NAME] # Name of the app -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database # Default: sqlite3 # Possible values: mysql, trilogy, postgresql, sqlite3, mariadb-mysql, mariadb-trilogy -G, [--skip-git] # Skip git init, .gitignore and .gitattributes [--skip-docker] # Skip Dockerfile, .dockerignore and bin/docker-entrypoint [--skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer] # Skip Action Mailer files [--skip-action-mailbox] # Skip Action Mailbox gem [--skip-action-text] # Skip Action Text gem -O, [--skip-active-record] # Skip Active Record files [--skip-active-job] # Skip Active Job [--skip-active-storage] # Skip Active Storage files -C, [--skip-action-cable] # Skip Action Cable files -A, [--skip-asset-pipeline] # Indicates when to generate skip asset pipeline -J, --skip-js, [--skip-javascript] # Skip JavaScript files [--skip-hotwire] # Skip Hotwire integration [--skip-jbuilder] # Skip jbuilder gem -T, [--skip-test] # Skip test files [--skip-system-test] # Skip system test files [--skip-bootsnap] # Skip bootsnap gem [--skip-dev-gems] # Skip development gems (e.g., web-console) [--skip-thruster] # Skip Thruster setup [--skip-rubocop] # Skip RuboCop setup [--skip-brakeman] # Skip brakeman setup [--skip-ci] # Skip GitHub CI files [--skip-kamal] # Skip Kamal setup [--skip-solid] # Skip Solid Cache, Queue, and Cable setup [--dev], [--no-dev], [--skip-dev] # Set up the application with Gemfile pointing to your Rails checkout [--devcontainer], [--no-devcontainer], [--skip-devcontainer] # Generate devcontainer files [--edge], [--no-edge], [--skip-edge] # Set up the application with a Gemfile pointing to the 8-0-stable branch on the Rails repository --master, [--main], [--no-main], [--skip-main] # Set up the application with Gemfile pointing to Rails repository main branch [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api], [--skip-api] # Preconfigure smaller stack for API only apps # Default: false [--minimal], [--no-minimal], [--skip-minimal] # Preconfigure a minimal rails app -j, --js, [--javascript=JAVASCRIPT] # Choose JavaScript approach # Default: importmap # Possible values: importmap, bun, webpack, esbuild, rollup -c, [--css=CSS] # Choose CSS processor. Check https://github.com/rails/cssbundling-rails for more options # Possible values: tailwind, bootstrap, bulma, postcss, sass -B, [--skip-bundle] # Don't run bundle install [--skip-decrypted-diffs] # Don't configure git to show decrypted diffs of encrypted credentials Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend], [--skip-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet], [--skip-quiet] # Suppress status output -s, [--skip], [--no-skip], [--skip-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help], [--skip-help] # Show this help message and quit -v, [--version], [--no-version], [--skip-version] # Show Rails version number and quit Description: The `rails new` command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time `rails new` runs in the .railsrc configuration file in your home directory, or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set. Note that the arguments specified in the .railsrc file don't affect the default values shown above in this help message. You can specify which version to use when creating a new rails application using `rails _<version>_ new`. Examples: `rails new ~/Code/Ruby/weblog` This generates a new Rails app in ~/Code/Ruby/weblog. `rails _<version>_ new weblog` This generates a new Rails app with the provided version in ./weblog. `rails new weblog --api` This generates a new Rails app in API mode in ./weblog. `rails new weblog --skip-action-mailer` This generates a new Rails app without Action Mailer in ./weblog. Any part of Rails can be skipped during app generation. 不要そうなオプション(skip しても良さそうなオプション) –skip-docker Skip Dockerfile, .dockerignore and bin/docker-entrypoint ここでいう Dockerfile は Deploy 用のため他ツールを使用する場合は不要 –skip-asset-pipeline api モードではアセットは使用しないため不要 –skip-javascript api モード では javascript は使用しないため不要 –skip-hotwire api モード では Hotwire は使用しないため不要 –skip-jbuilder jbuilder 以外の gem を使用する場合は不要 –skip-test rspec 使用の場合は不要 –skip-system-test rspec 使用の場合は不要 –skip-thruster api モード では HTTP/2プロキシ「Thruster」は使用しないため不要 –skip-kamal Deploy tool に他を使用する場合は不要 –skip-devcontainer devcontainer を使用しない場合は不要 –skip-bundle bundle install をさせたくない場合は不要 必要そうなオプション(skip しない方が良さそうなオプション) –skip-git Skip git init, .gitignore and .gitattributes git 関連のファイルを作成しない –skip-keeps Skip source control .keep files .keep ファイルを作成しない 空のディレクトリを Git に含めるために必要 –skip-rubocop ruby コードの静的チェック –skip-brakeman ソースコードに、SQL インジェクションや XSS 等の脆弱性がないかを解析してくれる Gem –skip-ci GitHub CI files を生成しない –skip-active-record Active Record を使用しない –skip-active-storage Active Storage を使用しない FE からファイルアップロードを行う場合は必要 –skip-bootsnap bootsnap を使用しない bootsnap は起動を高速化させるので必要 –skip-dev-gems Gemfile 内の development 記載をしない development の gem を自分で記載する場合は必要 –skip-active-job Active Job(Queue 機能)を使用する場合は必要 –skip-action-cable Active Cable(Websocket 通信)を使用する場合は必要 –skip-solid 以下の機能を使用する場合は必要 Solid Cache(Cache 機能) Queue(Queue 機能) Cable(Websocket 通信) –skip-action-mailer Action Mailer を使用する場合は必要 –skip-action-mailbox Action Mailbox を使用する場合は必要 –skip-action-text Action Text を使用する場合は必要 使用例 App Name: myapp

Rails 8 リリースノートまとめ

  • POST
Rails 8 リリースノートについてまとめたものを備忘録として残しておく Rails 7 リリースノートまとめ Rails 7.1 リリースノートまとめ Rails 7.2 リリースノートまとめ Rails 8 系での新機能および変更点 Kamal(Docker コンテナのデプロイツール) Kamalという Docker コンテナを本番環境に簡単にデプロイするツールが同梱されるようになった ※Rails アプリケーションのデプロイで使用されていた Capistrano をコンテナように置き換えたツールのイメージ Thruster(HTTP/2 プロキシサーバ) Rails アプリケーションの Docker ファイルに、Thruster と呼ばれるプロキシサーバの設定が含まれ、Puma の前段に配置するようになった これにより、Nginx など別の Web サーバーを用意する必要がなくなる Thrusterの機能 HTTP/2のサポート Let’s Encrypt による自動化された TLS 証明書の管理 公開アセット(JavaScript、CSS、画像など)の HTTP キャッシュ X-Sendfile のサポートと圧縮 Solid Cable Solid Cable によって Redis を使用せずに WebSocket を使用したリアルタイム機能を使用することができる Solid Cache Solid Cache によってメモリを使用した Redis や Memcached よりも長期間にわたって大容量のアプリケーションのデータのキャッシュを行うことができる Solid Queue Solid Queue は、Redis を使用した Sidekiq や Resque といったジョブ実行システムと同様に、単純なジョブのエンキューや実行だけでなく、遅延実行、同期処理の制御、定期(繰り返し)実行、キューの停止、優先順序づけなど本格的な実用に耐えるものが実現できる

Rails 7.2 リリースノートまとめ

  • POST
Rails 7.2 リリースノートについてまとめたものを備忘録として残しておく 他バージョンのリリースノートまとめ Rails 7 リリースノートまとめ Rails 7.1 リリースノートまとめ Rails 7.2 系での新機能および変更点 開発用のDockerコンテナ(devコンテナ) Docker コンテナをフル機能の開発環境として使用できる dev コンテナと呼ばれる新機能が追加されました。 デフォルトでは、以下のようなコンテナが含まれています。 データベース(SQLite, PostgreSQL, MySQL, MariaDBなど) Active Storage Redis システムテスト(Headless Chrome) 新規のアプリケーションで dev コンテナを使用するには、rails new でアプリケーションを生成する際に --devcontainer オプションを追加する rails new myapp --devcontainer YJIT のデフォルト化 YJIT は Ruby の JIT コンパイラで、有効にすることで Rails アプリケーションのパフォーマンスを大幅に向上させ、レイテンシを15〜25%改善することができる Rails 7.2 で Ruby 3.3以上を使用している場合は、YJIT がデフォルトで有効となる 無効にする場合は以下の設定が必要 Rails.application.config.yjit = false ブラウザのバージョンの Guard デフォルト化 アプリケーション生成時に以下の設定が Application Controller に追加されるようになった allow_browser versions: :modern リクエストのヘッダの User-Agent に基づいて、モダンブラウザ(WebP画像、Import maps、CSS入れ子などの機能をサポート)のアクセスを許可する ※古いバージョンのブラウザに対しては許可せず、HTTP status 406を返す ※User-Agent がリクエストのヘッダに含まれない場合もアクセスを許可するため注意

Rails 7.1 リリースノートまとめ

  • POST
Rails 7.1 リリースノートについてまとめたものを備忘録として残しておく 他バージョンのリリースノートまとめ Rails 7 リリースノートまとめ Rails 7.1 系での新機能および変更点 Dockerfileの生成 新規アプリケーションで Dockerfile が自動生成されるようになった 複合プライマリキーのサポート 複合プライマリキーがサポートされ、マイグレーションや、Active Record のクエリメソッドなど Rails のアプリケーション全般で使用できるようになった DB に複合プライマリキーを使用したテーブルを作成するには、以下のようにマイグレーションの change_table の primary_key: オプションにカラム名の配列を渡す class CreateBooks < ActiveRecord::Migration[7.1] def change create_table :books, primary_key: [:store_id, :sku] do |t| t.integer :store_id t.string :sku t.string :name t.text :description end end end 使用例 クエリメソッド Product.find([3, "XYZ12345"]) # store_id: 3, sku: "XYZ12345"を指定 Product.where(Product.primary_key => [[1, "ABC98765"], [7, "ZZZ11111"]]) # store_id: 3, sku: "XYZ12345"とstore_id: 7, sku: "ZZZ11111" Product.first # SELECT * FROM products ORDER BY products.store_id ASC, products.sku ASC LIMIT 1 モデルの関連 従来の id ではなく、複合プライマリキーを使用するには、has_many や belongs_to などのオプションで query_constraints を使用する

Rails 7 リリースノートまとめ

  • POST
Rails 7 リリースノートについてまとめたものを備忘録として残しておく Rails 7 系での新機能および変更点 JavaScriptフロントエンドの刷新 ESM(ECMAScript modules)や import maps を使用し、Node.js をインストールせずにモダンな JavaScript が利用可能 ※デフォルトでは Hotwire, Stimulus, Turbo がインストールされる CSS Bundling 以下のサポートが追加 Tailwind CSS PostCSS アプリケーション新規作成時に指定可能 rails new myapp --css tailwind 既存に追加する場合は Gemfile に以下を追加して gem 'cssbundling-rails' 以下のコマンドを実行することでインストールおよび初期設定が可能 bin/bundle install bin/rails css:install:tailwind Active Recordの実行時暗号化機能 データの暗号化が可能になった bin/rails db:encryption:init コマンドを実行してランダムなキーを生成 結果をbin/rails credentials:editで開いたエディタの画面に貼り付けて保存 Model で以下のように指定 class User < ApplicationRecord encrypts :name end Spring のデフォルト値の変更 大規模なアプリケーション以外では Spring があまり意味をなさなくなったため、デフォルトがオフに変更 Sass と CSS ジェネレータの非標準化 最近では CSS フレームワークを使うようになっているため、Sass は使用されなくなってきている そのため sass-rails Gem が標準では Gemfile に含まれないようになった また、自動生成される CSS ファイルも拡張子が .scss ではなく .css のファイルになった そして、モデルごとに CSS ファイルを生成しないようになった

Tbls についての Tips

  • POST
Tbls についての Tipsを備忘録として残しておく 環境 OS: macOS 15.3 手順 Tbls について 実際の DB に接続してテーブル定義書を生成してくれるツール 様々な形式(markdown, Excel 等)で生成してくれる ※詳細は Tbls を参照 設定ファイルについて # # @see https://github.com/k1LoW/tbls # # Data Source Name ## @see https://github.com/k1LoW/tbls#dsn # dsn: postgres://<<user>>:<<pass>>@localhost:5432/<<dbname>> # To connect with SSL mode disabled # dsn: postgres://<<user>>:<<pass>>@localhost:5432/<<dbname>>?sslmode=disable # DSN configuration values should be found in the .env file TBLS_DSN # Disable output of schema data # Default is false disableOutputSchema: false format: # Adjust the column width of Markdown format table # Default is false adjust: true # Sort the order of table list and columns # Default is false sort: false # Display sequential numbers in table rows # Default is false number: false # The comments for each table in the Tables section of the index page will display the text up to the first double newline (first paragraph). # Default is false showOnlyFirstParagraph: true # Hide table columns without values # Default is false hideColumnsWithoutValues: false # It can be boolean or array # hideColumnsWithoutValues: ["Parents", "Children"] er: # Skip generation of ER diagram # Default is false skip: false # ER diagram image format (`png`, `jpg`, `svg`, `mermaid`) # Default is `svg` format: mermaid # Add table/column comment to ER diagram # Default is false comment: false # Hide relation definition from ER diagram # Default is false hideDef: true # Show column settings in ER diagram. If this section is not set, all columns will be displayed (default). showColumnTypes: # Show related columns related: true # Show primary key columns primary: true # Distance between tables that display relations in the ER # Default is 1 distance: 1 # ER diagram (png/jpg) font (font name, font file, font path or keyword) # Default is "" ( system default ) font: "" detectVirtualRelations: enabled: true strategy: default # Exclude tables exclude: - goose_db_version docPath: docs/ja/ comments: - table: mst_books tableComment: |- 書籍情報を管理するテーブル columnComments: name: 書籍名 TBLS_DSN=postgres://postgres:postgres@localhost:5432/olbdb?sslmode=disable 出力ファイルの上書きについて # markdown tbls doc --config .tbls.yml --rm-dist # Excel tbls out --config .tbls.yml -t xlsx -o schema.xlsx DSN の設定について ローカルで実施する場合は以下のどちらかで可能

Terminal Ghostty の設定方法

  • POST
Terminal Ghostty の設定方法について調査した結果を備忘録として残しておく 環境 OS: macOS 14.7 手順 Ghostty のセットアップ フォントのインストール brew install --cask font-monaspace # Hack Nerd Font brew install font-hack-nerd-font # HackGen brew install font-hackgen # HackGen Nerd brew install font-hackgen-nerd 以下のコマンドを実行する brew install --cask ghostty mkdir -p ~/.config/ghostty vim ~/.config/ghostty/config config ファイルを修正する 設定値については参考を参照 theme = iTerm2 Pastel Dark Background font-family = HackGen35 Console NF font-size = 16 macos-non-native-fullscreen = true macos-titlebar-proxy-icon = hidden macos-titlebar-style = tabs window-padding-x = 20 window-padding-y = 20 # クイックターミナルの位置を画面下部に設定 quick-terminal-position = "bottom" # クイックターミナルを表示するスクリーンを設定 (メインスクリーン) quick-terminal-screen = "main" # アニメーション時間を設定(0で即時表示) quick-terminal-animation-duration = 0 # グローバルホットキーを設定 keybind = "global:ctrl+cmd+`=toggle_quick_terminal" Ghostty チートシート キーバインディング内容⌘+T新規タブ作成⌘+[ or ⌘+]タブを移動⌘+D横にスプリット⇧+⌘+D縦にスプリット⌘+[ or ⌘+]スプリットを移動⇧+⌘+↵スプリットをズーム、ズームアウトoption+clickクリックしたところにカーソルを合わせられます テーマのプレビュー ghostty +list-themes