Skip to content
  • There are no suggestions because the search field is empty.

How do I integrate Prerender.io with Ruby on Rails?

Connect Prerender.io to your Rails server so AI crawlers and search engines receive fully rendered HTML.

TL;DR

Add the prerender_rails gem to your Rails application, configure it with your Prerender.io token in your production environment, and restart your server. The gem uses Rack middleware to detect AI crawlers and search engine bots and route their requests through Prerender.io's rendering service. Your website visitors are not affected.

⚠️ This integration is for Rails applications where Rails handles all incoming HTTP requests. If your Rails app only serves an API and a separate frontend framework (React, Angular, Vue) handles routing, see how to integrate Prerender.io with a Single Page Application instead.

ℹ️ Prefer a video walkthrough? A video guide is available here

Video guide:

 

Step 1: log in to your Prerender.io dashboard and copy your token.

You will need your Prerender.io token for Step 3. Log in to your Prerender.io dashboard and find your token under the Security and Access menu.

Copy the token and keep it ready.

Step 2: add the prerender_rails gem to your Gemfile.

Open the Gemfile in the root directory of your Rails project and add the following line:

gem 'prerender_rails' 
 

image(67)

Save the file and run the following command in your terminal to install the gem:

bundle install

The source code for the gem is available on GitHub.

Step 3: configure Prerender.io in your production environment.

Open your production configuration file, typically located at config/environments/production.rb, and add the following line:

 config.middleware.use Rack::Prerender, prerender_token: 'YOUR_TOKEN'
 
 

Replace YOUR_TOKEN with the Prerender.io token you copied in Step 1.

image(68)


⚠️ Do not commit your real token to a public repository. Use an environment variable (e.g., ENV['PRERENDER_TOKEN']) to keep it secure.

Save the file.

Step 4: restart your Rails server.

Restart your server using your normal deployment process. For example:

 # Puma
pumactl restart

# Passenger
passenger-config restart-app /path/to/app

# Systemd
sudo systemctl restart your-rails-app
 

ℹ️ For local development and testing, you can use rails server to start a fresh server process. In production, always restart using your process manager or deployment pipeline.

 

Step 5: verify your integration is working.

After restarting, confirm that Prerender.io is intercepting crawler requests and serving rendered HTML.

You can test with a curl command using a crawler user-agent:

curl -v -A "Googlebot" https://www.yoursite.com/ 
 
 

Check the response headers for the x-prerender-request-id header. When using the hosted Prerender.io service, this header confirms Prerender.io is serving the page.

Alternatively, follow the full verification guide for step-by-step instructions using Chrome DevTools.

✅ Your integration is working when a simulated bot request returns an x-prerender-request-id response header (hosted Prerender.io service) and cached pages appear in your Prerender.io dashboard.

If the integration works on your homepage but not on other pages, test those pages individually. Missing Prerender.io headers on specific pages usually means the middleware is not intercepting requests for those routes. Run rails middleware to inspect your middleware stack and confirm Rack::Prerender is positioned before any middleware that might intercept bot requests (such as caching or authentication layers). If needed, use config.middleware.insert_before in production.rb to reposition it.

If you see the message Prerender Integration Not Detected, follow the troubleshooting guide for integration detection errors.


Related articles



💬 Still need help? If your integration is not working after following these steps, our support team can help. Include any error messages, the steps you have already tried, and screenshots if applicable. → Contact us at support@prerender.io

 

Was this article helpful?