1
<%= if @meta_leeds == "leeds" %>
  <meta property="og:image" content="http://www.some.link/to/image"/>
<% end %>

I want to embed a specific meta tag only on one page of my rails application. I defined :

@meta_leeds = "leeds"

in the pages' controller and it will display the string when put between a h1 tag but it will not output the meta tag based on the outcome of the above if statement.

What am i doing wrong?

tereško
  • 58,060
  • 25
  • 98
  • 150

2 Answers2

0
<% if @meta_leeds == "leeds" %>
  <meta property="og:image" content="http://www.some.link/to/image"/>
<% end %>

Just remove the = (and only the =) from the statement.

Matt
  • 13,948
  • 6
  • 44
  • 68
  • Great, this seems to have worked! But i'm confused as I thought ' = ' was meant for assigning a value to a variable and ' == ' was a comparison operator. Why does this work as a definition operator rather than a comparison operator? – Louis Jones Jan 29 '16 at 12:23
  • @LouisJones It doesn't, you're confusing erb and Ruby. – Dave Newton Jan 29 '16 at 13:11
0

So i managed to embed the meta tag by checking the title rather than if the variable that was in a controller function was present.

Here is the final working code :

<% if yield(:title) == "Leeds" %>
  <meta property="og:image" content="http://www.some.link/to/image"/>
<% end %>