Rendering a string as a color hex value in Ruby on Rails
I have a hex value that I am getting from an XML file and I am trying to use that hex value as the background color for a data table. However, in IE8 it keeps rendering as a string.
When I have used
<%= h(@dhex1[k]) %>
it renders as
<%hex>A8960A<%/hex> with 开发者_如何学编程hex tags (note % signs are so browser does not think they are tags)
in the browser. I have tried
<td style="background-color:#<%=h(@dhex1[k].to_s)%>">
<td style="background-color:#<%=h(@dhex1[k])%>">
<td style="background-color:#<%=@dhex1[k]%>">
<td style="background-color:<%=@dhex1[k]%>">
yet it will not render as a background color. The hex tags how the value is stored the XML doc itself and I am using
@hex1 = XPath.match( xmldoc, "///hex" )
to get the hex value, but it renders as A8960A. What do I need to change?
From your description, it seems that @dhex1[k]
conatins an unwanted xml element. Either get rid of that at the place where you extract the value, as in
@hex1 = XPath.match(xmldoc, '//hex/text()')
or later, as in
<td style="background-color:#<%= @dhex1[k].gsub(/<.+?>/, '') %>">
精彩评论