<!-- Generated from ja/llms-txt-rails/index.html. The canonical document is the HTML page. -->

- [ ホーム ](/ja/) 
/
- [ llms.txtの作成方法 ](/ja/how-to-create/) 
/
- Ruby on Rails            
# Ruby on Railsでの`llms.txt`

Rails はサイトのルートで public/ フォルダーを提供します。そこに llms.txt を追加するか、コンテンツが動的な場合はコントローラーから生成します。

最終更新: 2026年7月26日

このページの内容

- [ 2つのアプローチ ](#overview)
- [ 方法1：public/内の静的ファイル ](#public)
- [ 方法2：コントローラーアクション ](#controller)
- [ 本番環境での静的ファイル配信 ](#production)
- [ 設定の確認 ](#verify)            
## 2つのアプローチ

Railsでは `llms.txt` を2つの方法で配信できます： `public/` （最も簡単な方法）、
またはデータからファイルを生成するコントローラーアクションです。コンテンツを最新のレコードに反映する必要がない限り、静的ファイルを使用してください。

## 方法1：public/内の静的ファイル

`public/` 内のすべてのファイルはドメインのルートで配信されます。次の場所にあるファイル：
`public/llms.txt`
次に解決されます： `/llms.txt`.

- ファイルを作成します: `touch public/llms.txt` 
- コンテンツを書きます（ [作成方法ガイド](/ja/how-to-create/)):   
```
# Your App Name

> One-sentence description of your app for LLM context.

## Core pages

- [Home](https://yourdomain.com/): what this app does.
- [Pricing](https://yourdomain.com/pricing/): plans and limits.
- [Docs](https://yourdomain.com/docs/): developer documentation.

```

## 方法2：コントローラーアクション

ファイルを動的に生成するには、プレーンテキストをレンダリングするルートとコントローラーを追加します：

```
# config/routes.rb
get "/llms.txt", to: "llms#show"

# app/controllers/llms_controller.rb
class LlmsController   Description of your app.\n\n## Core pages\n\n"
body += pages.map { |p| "- [#{p.title}](#{page_url(p)}): #{p.summary}" }.join("\n")
render plain: body, content_type: "text/plain"
end
end

```

## 本番環境での静的ファイル配信

警告

public_file_server

Railsはデフォルトでは  public/  本番環境では、フロントエンドのWebサーバーまたはCDNがこれを担当します。
Rails自体がファイルを提供する必要がある場合（例：一部のPaaS上）、次のように設定してください。
config.public_file_server.enabled = true  または
RAILS_SERVE_STATIC_FILES  環境変数。コントローラーメソッド（方法 2）は、 この設定にかかわらず
Rails によって提供されます。

## 設定の確認

```
curl -sI https://yourdomain.com/llms.txt | grep -i content-type
# expect: content-type: text/plain
```

Laravelを使用している場合は、 [Laravelガイド](/ja/llms-txt-laravel/)。ページコンテンツをより完全に 書き出すには、 [`llms-full.txt`](/ja/llms-full-txt/).

## ソース

- [ Railsガイド、設定（public_file_server） ](https://guides.rubyonrails.org/configuring.html)
- [ llmstxt.org、仕様リファレンス ](https://llmstxt.org/)
