Ruby on rails 在Rails 4中使用胡须模板作为局部视图?

Ruby on rails 在Rails 4中使用胡须模板作为局部视图?,ruby-on-rails,ruby-on-rails-4,mustache,Ruby On Rails,Ruby On Rails 4,Mustache,我试图在Rails4中使用mustache视图,而不是一些旧的局部视图,它们承载了一些与javascript应用程序共享的HTML模板 添加了config/initializers/mustache.rb # Tell Rails how to render mustache templates module MustacheTemplateHandler def self.call(template) #assigns contains all the instance_varia

我试图在Rails4中使用mustache视图,而不是一些旧的局部视图,它们承载了一些与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)
我将我的模板命名为
\u template.mustache
并将其放入
视图/sales/\u template.mustache
中,我可以使用
渲染部分:“模板”

我应该把
Template.rb
文件放在哪里,以便它处理胡子

class Template < Mustache

  def something
    # return something
    "WOW"
  end

end
类模板
因此,您可以将这些变量直接写入控制器