Q:

Link tag printing rather than being interpreted

I am trying to include a css file in a layout file on a rails site and my  tag contained in the header is not being interpreted, it is instead displaying on the page.  I put the tag in the  section.  The link tag is shown below.  I assign page_style and it is correctly inserted on the page but the page displays the second tag below instead of interpreting the tag.
<%= "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/#{@page_style}.css\">"    if !@page_style.nil? %>

<link rel="stylesheet" type="text/css" href="/stylesheets/standard.css">

A:

In Rails (3 and up), strings are HTML-escaped before being shown, so your < are being encoded as &lt;, etc.
You can add .html_safe to your string like this:
<%= "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/#{@page_style}.css\">".html_safe if !@page_style.nil? %>

However, it would be a bit more Rails-y if you rewrote it to use the stylesheet_link_tag helper like this:
<%= stylesheet_link_tag(@page_style) if @page_style.present? %>

