vanhiro
vanhiro

Reputation: 305

How can I use meta-tags gem?

I'm using meta-tags gem for rails.

and I set meta tags below.

application.html.erb

<%= csrf_meta_tags %>
<%= display_meta_tags({
:title => "" ,
:site => t('site') ,
:description => '',
:keywords => '',
:viewport => "width=device-width, initial-scale=1.0" ,
:reverse => true
})%>

and here is view file.

view.erb

<% set_meta_tags 
    title '@hoge.title',
    description '#{@hoge.neme} is awesome'
 %>

It cause syntax error. How can I write proper way?

Upvotes: 0

Views: 671

Answers (2)

basiam
basiam

Reputation: 1567

In order to get rid of this syntax error you should pass the title and description to set_meta_tags as a hash, just like you did for display_meta_tag. More than one syntax version will work, you can read more about hash syntax http://docs.ruby-lang.org/en/2.0.0/Hash.html

<% set_meta_tags({
    :title => '@hoge.title',
    :description => '#{@hoge.neme} is awesome'
 })%>

or

<% set_meta_tags({ 
    title: '@hoge.title',
    description: '#{@hoge.neme} is awesome'
})%>

Upvotes: 0

Dushyant
Dushyant

Reputation: 4960

Here you go (It has comprehensive solution on how to use meta-tags with rails 4 app) http://www.buggingcode.com/adding-meta-tags-in-rails-4-app-for-each-post-in-views

Upvotes: 1

Related Questions