Meta tags are used for search engine optimization.Using meta tags we can control how are website should look on social sites when it is shared.
There are two important meta tags:
Meta description tags
Meta keyword tags
Some search engines display the meta description as a part of the search results, but the meta keyword tags should not appear in search results.
Ruby on rails MetaTags gem makes rails application SEO-friendly
Add the "meta-tags" gem to your Gemfile.
gem 'meta-tags'
And run bundle install command.
Once installation is done,create an initializer config/initializers/meta_tags.rb, with following code:
MetaTags.configure do |c|
c.title_limit = 70
c.description_limit = 160
c.keywords_limit = 255
c.keywords_separator = ', '
end
These limits are default values, but we can change them as per our requirements.
Open Graph:
Using MetaTag gem we can make our webpages as a graph objects so that our web page can be surfaced within Facebook. For that we need to add Open graph
tags to our webpage.
Meta tags are included in the Head section of the HTML page For Example.
<head>
set_meta_tags og: {
title: 'My image',
type: 'image',
image: 'image_url',
}
<%= display_meta_tags %>
</head>
This will generate the following HTML.
<meta property="og:title" content="My image"/>
<meta property="og:type" content="image"/>
<meta property="og:image" content="image_url">
0 Comment(s)