2017-07-04 19 views
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 

回答

0

所以,你可以直接写这个变量给你的控制器。