我试图在Rails 4中使用小胡子视图,而不是托管我与javascript应用程序共享的一些HTML模板的旧部分视图。
添加了config / initializers / mustache.rb
# Tell Rails how to render mustache templates
module MustacheTemplateHandler
def self.call(template)
#assigns contains all the instance_variables defined on the controller's view method
"Mustache.render(#{template.source.inspect}, assigns).html_safe"
end
end
# Register a mustache handler in the Rails template engine
ActionView::Template.register_template_handler(:mustache, MustacheTemplateHandler)
我将模板命名为_template.mustache
,并将模板放在views/sales/_template.mustache
中,我可以使用.html.erb
render partial: 'template'
进行渲染
我在哪里放Template.rb
文件来处理小胡子?
class Template < Mustache
def something
# return something
"WOW"
end
end
答案 0 :(得分:0)
因此,您可以将此变量直接写入您的控制器。