To use SEO.js with a Rails app add the seojs gem to your Gemfile:
gem 'seojs'
Afterwards
$ bundle install
Configure your API key
Create a new file config/initializers/seojs.rb in your project and set the API key. (Replace YOUR_API_KEY with your real API key that you got when signing up)
Seojs.token = "YOUR_API_KEY"
Alternatively, if you prefer to keep credentials separate from code you can set the SEOJS_TOKEN environment variable and leave the initializer empty.
If you’re using Sinatra or plain Rack instead of Rails you need to configure the middleware in your config.ru file:
require 'seojs'
Seojs.token = "your_secret_api_token"
use Seojs::Middleware
Requests to your app containing the _escaped_fragment_ query parameter will now be forwarded to our CDN.
Enable AJAX crawling
To tell search engine crawlers that your site allows AJAX crawling you need to add the fragment meta tag to your HTML header.
...
Use compatible URLs
Your URLs need to be in one of these formats:
- /nice#!page – they are Hashbang URLs
- /nice/page – they are HTML5 PushState URLs
Hashbang URLs are easier to implement and are compatible with older browsers, but many users find PushState URLs look more convenient.
Hash fragment URLs without the exclamation mark cannot be crawled:
/one#page needs to be changed to /one#!page or /one/page