Ruby/Rails stripping quotes...

25 views
Skip to first unread message

jmcguckin

unread,
May 18, 2015, 8:54:28 PM5/18/15
to rubyonra...@googlegroups.com
Rather than setting the <meta name="description" contents="xyzzy"> 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

Dave Aronson

unread,
May 18, 2015, 9:02:01 PM5/18/15
to rubyonrails-talk
On Mon, May 18, 2015 at 8:54 PM, jmcguckin <mcgu...@gmail.com> 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:

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

Don't overthink it. :-) 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 Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.

jmcguckin

unread,
May 18, 2015, 9:26:52 PM5/18/15
to rubyonra...@googlegroups.com
Thanks! That worked perfectly!!

-joe
Reply all
Reply to author
Forward
0 new messages