giorgi topuria giorgi topuria - 2 months ago 17
CSS Question

link CSS file to Haml layout Template

I am trying to link

css
file to
haml
layout template

I have method in
ApplicationHelper
to generate proper
html


module ApplicationHelper

def styletag(sheet_name)
"<link rel='stylesheet' href='/assets/stylesheets/#{sheet_name}.css'>"
end

end


and also link to layout template

!!! 5
%html
%head
%title Rotten Potatoes!
= stylesheet_link_tag 'application'
= styletag 'default'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
= yield


but it seems like
haml
doesn't consider it like a tag and it's displayed like a text.

Answer

You need to add html_safe. Rails by default is escaping the html in your text so you need to tell rails that it should not do so.

See http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/stylesheet_link_tag and click "Show Source" If you change it to this:

def styletag(sheet_name)
    "<link rel='stylesheet' href='/assets/stylesheets/#{sheet_name}.css'>".html_safe
end

it should work for you