Handlebar / erb模板和Ruby助手

时间:2014-12-19 23:21:38

标签: ruby-on-rails-4 handlebars.js

我试图通过* .handlebars.erb模板在我的车把模板中使用Ruby,但是在所有其他rails视图模板中工作的Ruby助手似乎不能在那里工作。我正在使用' ember-rails' gem,用于处理向资产管道添加车把模板。

application_helper.rb

module ApplicationHelper
  def foo_bar
    "boo"
  end
end

foo.handlebars.erb

<p>Build Date: <%= foo_bar %></p>
{{#if view.isLoaded }}
    ...
{{/if}}

Ruby错误

undefined local variable or method `foo_bar' for #<#<Class:0x007fa4fbfc6a50>:0x007fa4fddf9630>

如何在把手erb文件中包含应用程序助手?

1 个答案:

答案 0 :(得分:0)

看起来解决方案是创建一个初始化程序,将View帮助程序添加到资产上下文类中:

Rails.application.assets.context_class.class_eval do
  include ActionView::Helpers
  include Rails.application.routes.url_helpers
end

Source

相关问题