Rails (Ruby) Integration Guide
This guide will walk you through integrating Prerender into your Rails server, improving your SEO.
Integrating Prerender with your Rails server allows you to optimize your website for search engines by pre-rendering dynamic content for bots. This is particularly useful for Single Page Applications (SPAs) where content is loaded asynchronously, making it difficult for search engines to crawl and index properly. By using Prerender, you can ensure that crawlers receive a fully rendered version of your site, improving SEO and ensuring better visibility in search engine results.
Note: This guide uses Prerender’s prerender_rails
gem to integrate Prerender with your Rails server.
Installation and Setup
Video guide:
The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.
You can find the required codes in the text guide.
Text guide:
Step 1: Add the Prerender Gem to Your Gemfile
1. Open the Gemfile located in the root directory of your Rails project. Typically, this would be /home/rails/example/Gemfile
.
2. Add the middleware gem by inserting the line below into you project's Gemfile.
Usually located at /<project root directory>/Gemfile
gem 'prerender_rails'
3. Save the file and run the following command in your terminal to install the gem:
bundle install
Step 2: Configure Prerender in Production Environment
1. Locate the production configuration file in your Rails project. It is typically found at /home/rails/example/config/environments/production.rb
.
2. Add the following line to enable the Prerender middleware in the production environment:
config.middleware.use Rack::Prerender, prerender_token: 'YOUR_TOKEN'
Important: Make sure to replace the YOUR_TOKEN place holder with your Prerender.io Token from the Security and Access menu
- 3. Save the changes.
Step 3: Restart Your Rails Server
To apply the changes, restart your Rails server. This will allow Prerender to begin working with your application and pre-render content for crawlers.
rails server
Verify Your Installation
After integration, it’s important to verify that everything is working as expected. We’ve provided an easy-to-follow guide to help you test your setup and confirm that Prerender is functioning properly.
Or, test with curl
command with a custom User-Agent
header:
curl -v -A googlebot www.yourpage.com/
Is the Prerender integration working on other pages?
Test if the Prerender integration works on the other pages based on this guide: Verify the integration
If you don't see the Prerender headers / IDs, then the Integration is not working, which might be why the other URL is not cached
Getting an Error?
If you see the message "Prerender Integration Not Detected," you can refer to the troubleshooting guide here to help resolve the issue.
Expert Assistance
For those who need additional help or want to ensure a smooth and secure launch, we offer a specialized package:
Kickstart Package
Price: $800 (one-time payment)
This one-time package empowers you with expert setup and configuration, ensuring a smooth and secure launch.
Features:
- Three setup and configuration sessions with our experts
- Onboarding assistance
- Security assessment
To learn more about this package or to purchase, visit the Packages section under the Billing menu in your Prerender dashboard.
Get Support
If you're still encountering issues after implementing Prerender:
- Review your implementation against our documentation
- Contact our support team:
- Email: support@prerender.io
- Support Ticket: Submit a ticket
- Chat: Available from your Prerender dashboard
To help us resolve your issue as quickly as possible, please gather and include any relevant information, such as:
- Error messages you're seeing
- Steps you've already taken to troubleshoot
- Screenshots or screen recordings (if applicable)
Providing these details up front will help our team diagnose the problem more efficiently and get you back on track faster.
Related Articles / FAQs
- How Can I Integrate Prerender With My React/Angular/Vue Application?
- What are the best practices for using Prerender with single-page applications (SPAs)?
- Available integrations
- How to add multiple domains?
- How to integrate Prerender with Cloudflare?
- How to add additional bots (integrations maintained by Prerender)
- How to check cached versions of your URLs?
- Why Am I Seeing 403 or 404 Errors After Integrating Prerender?