0
我想在Rails 4中使用小胡子的视图,而不是一些旧的部分视图,这些视图托管了一些我正与javascript应用程序共享的HTML模板。使用小胡子模板作为Rails 4中的部分视图?
新增配置/初始化/ 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