Closed cmalpeli closed 7 years ago
You can use <% set_meta_tags description: 'Other description' %>
or <% description 'Other description' %>
in your views
Thanks for the quick reply! That is what I'm doing.
Main Layout:
<% set_meta_tags site: home_meta_title,
description: "Default description",
charset: "utf-8",
canonical: canonical_url,
icon: favicon,
viewport: "width=device-width, initial-scale=1, maximum-scale=1",
twitter:{widgets:{csp: "on"}} %>
<%= display_meta_tags reverse: true %>
My View:
<% set_meta_tags title: @job.seo_title, description: @job.short_description,
og: {
title: @job.title,
type: 'article',
url: @job.url,
image: @job.logo.opengraph,
site_name: @current_tenant.name } %>
But my output is:
<meta name="description" content="Default description" />
Checking, thank you for the report
Could you remove set_meta_tags
and pass arguments directly to display_meta_tags
? Like:
<%=
display_meta_tags(
site: home_meta_title,
description: "Default description",
charset: "utf-8",
canonical: canonical_url,
icon: favicon,
reverse: true,
viewport: "width=device-width, initial-scale=1, maximum-scale=1",
twitter: { widgets: { csp: "on" } },
)
%>
If you use set_meta_tags
in the layout – it will override the values you set in your views. If you pass values to display_meta_tags
– they will be used as defaults, and views will override the values.
That worked great - thanks!!
You're welcome
@kpumuk I am having a similar issue. I am trying to put in a default description, but when I use<%= display_meta_tags( description: 'Default description' ) %>
I get nothing back in the layout. I am using version 2.4.1 of the gem since I am on an earlier version of Ruby. Any advice?
@aapljack Could you provide more details?
display_meta_tags
declared? (layout? view?) If it is a layout, please make sure it is the one used for your controller.set_meta_tags
or description
helpers?@page_description
instance variable declared in your controller?@kpumuk Thanks for the response. Some details..
display_meta_tags
declared in the layout and it is the one being used by the controller.set_meta_tags
in the controller. To test, I have completely removed this from the controller and I still do not get the default description set in the display_meta_tags
.@page
set and am pulling in the description with @page.description
. When no description is present, I want it to fall back to the default.
Is there a way to provide a default meta description and then override it on a view by view basis? Similar to how