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

- [ Home ](/) 
/
- [ How to create llms.txt ](/how-to-create/) 
/
- Ruby on Rails            
# llms.txt in Ruby on Rails

Rails serves the public/ folder at the site root. Add llms.txt there, or generate it from a controller if the content is dynamic.

Last updated: July 26, 2026

## Two approaches

Rails can serve `llms.txt` two ways: a static file in `public/` (simplest),
or a controller action that builds the file from your data. Use the static file unless the content
must reflect live records.

## Method 1: static file in public/

Everything in `public/` is served at the domain root. A file at `public/llms.txt`
resolves to `/llms.txt`.

- Create the file: `touch public/llms.txt` 
- Write your content (see the [how-to guide](/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.

```

## Method 2: a controller action

To generate the file dynamically, add a route and a controller that renders plain text:

```
# 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

```

## Serving static files in production

⚠ public_file_server

By default Rails does not serve  public/  in production; a fronting web server or CDN does.
If Rails itself must serve the file (e.g. on some PaaS), set
config.public_file_server.enabled = true  or the
RAILS_SERVE_STATIC_FILES  environment variable. The controller method (Method 2) is served
by Rails regardless of this setting.

## Verifying the setup

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

Using Laravel instead? See the [Laravel guide](/llms-txt-laravel/). For a fuller
export of page content, add [`llms-full.txt`](/llms-full-txt/).

## Sources

- [ Rails guides, configuring (public_file_server) ](https://guides.rubyonrails.org/configuring.html)
- [ llmstxt.org, spec reference ](https://llmstxt.org/)           
On this page

- [ Two approaches ](#overview)
- [ Method 1: static file in public/ ](#public)
- [ Method 2: a controller action ](#controller)
- [ Serving static files in production ](#production)
- [ Verifying the setup ](#verify)
