Does Ruby on Rails Work With WordPress?
Ruby on Rails and WordPress can coexist in the same project, but they're fundamentally different architectures that don't integrate deeply—you're essentially running two separate applications.
Quick Facts
How Ruby on Rails Works With WordPress
Rails and WordPress don't have native integration because they solve different problems: WordPress is a PHP-based CMS optimized for content management and plugins, while Rails is a full-stack Ruby framework for building custom web applications. The practical approach is running them as separate services. You can host WordPress on one subdomain (wordpress.example.com) for content management while Rails handles your application logic on the main domain. Alternatively, use the WordPress REST API from Rails to pull published posts, pages, or custom post types into your Rails application, treating WordPress as a headless CMS. This gives you WordPress's content editing UX without coupling the systems. Another pattern: embed Rails microservices as separate endpoints that WordPress calls via HTTP, useful when you need business logic that doesn't fit WordPress's PHP ecosystem. The main tension is deployment complexity—you're managing two different stacks, dependency chains, and databases. Most developers choose this route when they need WordPress's content management capabilities but require Rails's power for complex application features like real-time functionality, machine learning integrations, or sophisticated data processing.
Best Use Cases
Rails Controller Consuming WordPress REST API
bundle add httparty# app/controllers/posts_controller.rb
require 'httparty'
class PostsController < ApplicationController
include HTTParty
base_uri 'https://wordpress.example.com/wp-json/wp/v2'
def index
response = self.class.get('/posts', query: { per_page: 10 })
@posts = response.parsed_response
render json: @posts
end
def show
response = self.class.get("/posts/#{params[:id]}")
@post = response.parsed_response
render json: @post
end
end
# config/routes.rb
Rails.application.routes.draw do
resources :posts, only: [:index, :show]
endKnown Issues & Gotchas
Session management across domains breaks cookie-based authentication
Fix: Use token-based auth (JWT) or OAuth. WordPress can generate JWT tokens via plugins; Rails validates them via middleware.
Database synchronization complexity when Rails needs real-time WordPress data
Fix: Query WordPress REST API on-demand rather than syncing databases. Cache aggressively with Redis.
Deployment pipelines become complex managing two separate applications
Fix: Use Docker Compose for local development, containerize both services separately in production.
WordPress plugins may conflict with Rails APIs if both modify the same data endpoints
Fix: Establish clear API boundaries. Use separate databases or distinct data models for each system.
Alternatives
- •Next.js + WordPress: Headless WordPress with modern JavaScript frontend (tighter integration, easier deployment)
- •Strapi + Rails: Use Strapi as headless CMS with Rails backend (both Node/Ruby, more cohesive tooling)
- •Ghost + Rails: Lightweight Ghost CMS for content, Rails for application logic (cleaner separation of concerns)
Resources
Related Compatibility Guides
Explore more compatibility guides