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:

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

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

On Mon, May 18, 2015 at 8:54 PM, jmcguckin [email protected] wrote:

<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:

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


Dave A., consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.

Thanks! That worked perfectly!!

-joe

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs