Install the gem
Add the gem from the root of your Rails project directory.
bundle add opengraphplusAdd API key to development environment
There are several ways to configure secrets in Rails projects. Choose the way your project manages secrets to connect OpenGraph+.
Using environment variables
Creates the initializer and adds your API key to .env:
rails g opengraphplus:env $OGPLUS__API_KEYUsing Rails credentials
Creates the initializer and stores your API key in encrypted credentials:
rails g opengraphplus:credentials $OGPLUS__API_KEYRestart development server
Restart your development server to pickup the new opengraphplus gem and API key settings in the ./config/initializers/opengraphplus.rb file.
Add open_graph_meta_tags helper to layout
Add the following code to your layout file:
<html>
<head>
<%= open_graph_meta_tags %>
</head>
</html>
This will render the Open Graph meta tags in your layout that are needed to display images on your website.
Verify installation
Check that your pages have the required OpenGraph tags:
rails opengraph:verify http://localhost:3000Deploy to Production
Your API key is configured for development. Deploy to production using your normal process—your key will be available the same way it is locally.
Using Rails credentials? You’re done. Your key deploys with your code.
Using environment variables? Set OGPLUS__API_KEY in your production environment.