Does Ruby on Rails Work With Cloudflare Pages?

Partially CompatibleLast verified: 2026-02-20

Rails apps can deploy to Cloudflare Pages only as static sites or via Workers; dynamic server rendering isn't directly supported.

Quick Facts

Compatibility
partial
Setup Difficulty
Moderate
Official Integration
No — community maintained
Confidence
medium
Minimum Versions
Ruby on Rails: 6.0

How Ruby on Rails Works With Cloudflare Pages

Cloudflare Pages is fundamentally a static site host with serverless functions via Workers. Rails is a full-stack MVC framework designed for dynamic server rendering. You cannot run a traditional Rails application directly on Pages—there's no Ruby runtime. However, you have two viable paths: (1) Use Rails as a headless API backend hosted elsewhere (Heroku, Railway, etc.) and deploy a static frontend (built with Rails' asset pipeline or a separate JS framework) to Pages, or (2) Use Cloudflare Workers with a Ruby-to-WASM compiler or Node.js adapter to run lightweight Rails logic. Most developers choose option 1, treating Pages as a CDN/static host for compiled assets while their Rails API runs independently. This architecture actually aligns well with modern JAMstack principles—you get Rails' productivity for the backend API while Pages handles global distribution of frontend assets at no bandwidth cost.

Best Use Cases

Deploying Rails-generated static sites (blogs, documentation) built with Jekyll or Middleman to Pages for free global CDN
Using Rails as a headless API while deploying a Next.js/Vue frontend to Pages with automatic deployments from Git
Building a Rails SPA backend with a statically-built frontend that communicates via REST/GraphQL APIs
Leveraging Cloudflare Workers to handle lightweight API requests while Pages serves static assets, reducing Rails server load

Rails API + Cloudflare Pages Frontend Setup

bash
npm install -g wrangler && rails new myapp --api && npm create vite@latest frontend -- --template react
bash
# Rails API (config/initializers/cors.rb)
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'yoursite.pages.dev', 'localhost:3000'
    resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete]
  end
end

# Frontend (wrangler.toml)
name = "myapp-frontend"
main = "dist/index.html"
route = "/*"
zone_id = "your_zone_id"

[[routes]]
pattern = "/api/*"
zone_name = "example.com"

# Frontend fetch call (src/App.jsx)
const response = await fetch('https://api.example.com/posts')
const posts = await response.json()

Known Issues & Gotchas

critical

No Ruby runtime on Cloudflare Pages means you cannot run Rails server-side rendering directly

Fix: Use Rails as an API backend only, or pre-render all content to static HTML during build time

critical

Database connections and stateful sessions don't work on a static host; Pages functions are ephemeral

Fix: Keep authentication and data mutations on your Rails API server; Pages only serves cached/static content

warning

CORS issues when calling Rails API from Pages-hosted frontend

Fix: Configure Rails CORS middleware to allow your Pages domain, or proxy API requests through Cloudflare Workers

info

Build times can be slow if generating large static sites with Rails asset pipeline

Fix: Optimize Rails assets, use incremental builds, or split into smaller deployments

Alternatives

  • Next.js (Vercel) with Rails API backend—native React support with automatic static optimization
  • Remix on Cloudflare Workers with a separate Rails API—full-stack JS on Workers with Rails powering data layer
  • Astro deployed to Cloudflare Pages with Rails API—simpler static site generation with better DX for content-heavy sites

Resources

Related Compatibility Guides

Explore more compatibility guides