Ruby/Rails stripping quotes...

Rather than setting the tag in every webpage of my site, I decided to be clever and set a variable in each controller with the text and do:

<meta name=“description” contents=<%= @desc %> />

on the layout instead. The problem is that the generated text has a no quotes:

is what I end up with.

I’ve tried every variant of surrounding the text with quotes or using variable interpolation in strings to try to make this work.

Either I end up with no text passed into the layout, or I get

<meta name=“description” contents=&quotFOO BAR&quot/>

Which may actually be correct, but just looks odd.

I’ve actually decided to add the meta tag the old fashioned way, but now I’m curious as to why I can’t make this work.

Any ideas?

Thanks,

Joe

    <meta name="description" contents=<%= @desc %> />

...

The problem is that the generated text has a no quotes:

    <meta name="description" contents=FOO BAR/>

You can surround the <% whatever %> with quotes, just like the "description". IOW:

  <meta name="description" contents="<%= @desc %>" />

Don't overthink it. :slight_smile: So long as you're doing things the way Rails intends, it's all easy and obvious. The big fight comes when you disagree with The Rails Way....

-Dave

Thanks! That worked perfectly!!

-joe