1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails 8.1 新機能サマリ

Last updated at Posted at 2025-10-31

Rails 8.1 新機能サマリ

Rails 8.1がリリースされ、多くの新機能が追加されました。この記事では、公式リリースノートで確認できる主要な機能を簡単にまとめています。

📋 目次


Active Job Continuations(ジョブ継続機能)

長時間実行されるジョブを複数のステップに分割し、途中で一時停止や再開が可能になりました。再起動後も最後に完了したステップから処理を再開できます。

メリット

  • デプロイ時のジョブの中断と再開が容易になる
  • 長時間実行されるジョブの安全性が向上
  • リソースの無駄を削減

使用例

class ProcessImportJob < ApplicationJob
  include ActiveJob::Continuable

  def perform(import_id)
    @import = Import.find(import_id)

    # block format
    step :initialize do
      @import.initialize
    end

    # step with cursor, the cursor is saved when the job is interrupted
    step :process do |step|
      @import.records.find_each(start: step.cursor) do |record|
        record.process
        step.advance! from: record.id
      end
    end

    # method format
    step :finalize

    private
      def finalize
        @import.finalize
      end
  end
end

Structured Event Reporting(構造化イベントレポート)

Railsアプリケーション内で発生するイベントを、ソフトウェアで処理しやすい構造化された形式で記録できるインターフェースが提供されました。

メリット

  • ログの解析やモニタリングが効率的に行える
  • イベントの追跡と分析が容易になる
  • 一貫したフォーマットでログを管理

主な用途

  • パフォーマンス監視
  • エラートラッキング
  • ユーザー行動分析

特徴

  • 人間が読むのに適したデフォルトのRailsロガーとは別に、構造化イベントを生成
  • JSON形式など、機械的に処理しやすい形式で出力
  • ログ解析ツールとの統合が容易

Local CI(ローカルCI)

クラウドサービスを利用せず、ローカル環境で継続的インテグレーション(CI)を実行できる機能が追加されました。

メリット

  • インターネット接続がない環境でもCIを活用可能
  • セキュリティ要件の厳しい環境でも利用可能
  • CI/CDパイプラインのコスト削減

特徴

  • 完全にオフラインで動作
  • Docker ComposeやKubernetesなどとの連携
  • 既存のCI/CDツールとの互換性

主な用途

  • オフライン開発環境でのCI実行
  • セキュアな環境での継続的インテグレーション
  • 開発初期段階でのローカルCI環境構築
config/ci.rb
CI.run do
  step "Setup", "bin/setup --skip-server"
  step "Style: Ruby", "bin/rubocop"

  step "Security: Gem audit", "bin/bundler-audit"
  step "Security: Importmap vulnerability audit", "bin/importmap audit"
  step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error"
  step "Tests: Rails", "bin/rails test"
  step "Tests: Seeds", "env RAILS_ENV=test bin/rails db:seed:replant"

  # Requires the `gh` CLI and `gh extension install basecamp/gh-signoff`.
  if success?
    step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff"
  else
    failure "Signoff: CI failed. Do not merge or deploy.", "Fix the issues and try again."
  end
end

Markdown Rendering(Markdownレンダリング)

Markdown形式のテキストをRails内で直接レンダリングできる機能が標準で搭載されました。

メリット

  • コンテンツの作成と表示がより柔軟になる
  • ドキュメントの管理が容易になる
  • リッチテキストコンテンツの表示が簡単に

使用例

class Page
  def to_markdown
    body
  end
end

class PagesController < ActionController::Base
  def show
    @page = Page.find(params[:id])

    respond_to do |format|
      format.html
      format.md { render markdown: @page }
    end
  end
end

主な用途

  • ブログやドキュメントサイトでのコンテンツ表示
  • ユーザー生成コンテンツのMarkdown対応
  • リッチテキストコンテンツの管理

まとめ

Rails 8.1では、開発者の生産性向上とアプリケーションの機能強化を目的とした多くの新機能が追加されました。特に注目すべきは以下の点です:

  • ジョブ管理の改善: Active Job Continuationsによる信頼性の向上
  • 監視とログの強化: Structured Event Reportingによる可観測性の向上
  • 開発体験の向上: Local CI、Markdown Renderingなど開発効率の改善

これらの機能を活用することで、より強力で保守しやすいRailsアプリケーションを構築できます。


参考リンク


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?