[英]link CSS file to Haml layout Template
I am trying to link css
file to haml
layout template我正在尝试将
css
文件链接到haml
布局模板
I have method in ApplicationHelper
to generate proper html
我在
ApplicationHelper
有方法来生成正确的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.但似乎
haml
并不认为它是一个标签,而是像文本一样显示。
You need to add html_safe.您需要添加 html_safe。 Rails by default is escaping the html in your text so you need to tell rails that it should not do so.
默认情况下,Rails 会转义文本中的 html,因此您需要告诉 rails 它不应该这样做。
See http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/stylesheet_link_tag and click "Show Source" If you change it to this:请参阅http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/stylesheet_link_tag并单击“显示源”如果您将其更改为:
def styletag(sheet_name)
"<link rel='stylesheet' href='/assets/stylesheets/#{sheet_name}.css'>".html_safe
end
it should work for you它应该适合你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.