Ruby on rails 哈姆勒+;胡子

Ruby on rails 哈姆勒+;胡子,ruby-on-rails,ruby,haml,mustache,Ruby On Rails,Ruby,Haml,Mustache,我正在尝试创建一个带有Haml+Mustache的博客,但是字段“description”有一个CKEditor,因此该字段总是包含html标记,但是即使将“description.html\u safe”放在其中,Mustache也不会呈现为html 我的助手: def post_for_mustache(post) { post: { category: { url: category_order_path(:category => post.category.

我正在尝试创建一个带有Haml+Mustache的博客,但是字段“description”有一个CKEditor,因此该字段总是包含html标记,但是即使将“description.html\u safe”放在其中,Mustache也不会呈现为html

我的助手:

def post_for_mustache(post)
{
  post: {
    category: {
      url: category_order_path(:category => post.category.to_param),
      name: post.category.name
    },
    url: category_post_path(:category => post.category.to_param,
                            :slug => post.to_param),
    title: post.title,
    comment_enabled: post.comment_enabled,
    description: post.description.html_safe,
    title_escape: URI.escape(post.title),
    url_escape: URI.escape(category_post_url(:category => post.category.to_param,
                                             :slug => post.to_param)),
  }
}
end
我的胡子初始化器:

module MustacheTemplateHandler
  def self.call(template)
    haml = "Haml::Engine.new(#{template.source.inspect}).render"
    if template.locals.include? 'mustache'
      "Mustache.render(#{haml}, mustache).html_safe"
    else
      haml.html_safe
    end
  end
end
ActionView::Template.register_template_handler(:mustache, MustacheTemplateHandler)

我猜你在你的胡子上做了类似的事情:

{{description}}
如果
description
包含HTML,您需要说:

{{{description}}}
从:

变量
[…]
默认情况下,所有变量都是HTML转义的。如果要返回未缩放的HTML,请使用三重胡须:
{{{name}}


因此,
{{description}}
将通过胡须进行HTML编码,但是
{{{{descriptipn}}
将按原样使用
description

我猜你在你的胡子上做了类似的事情:

{{description}}
如果
description
包含HTML,您需要说:

{{{description}}}
从:

变量
[…]
默认情况下,所有变量都是HTML转义的。如果要返回未缩放的HTML,请使用三重胡须:
{{{name}}

因此,
{{description}}
将通过Mustache进行HTML编码,但是
{{{{descriptipn}}
将按原样使用
描述