在JSX资产中找不到Rails ERB路由助手_path方法

时间:2015-01-12 22:17:43

标签: ruby-on-rails ruby routes reactjs helper

我正在使用ReactJS编译一些JSX资产作为我的Rails 4应用程序的一部分(使用gem),尽管在{{3中指定了它们,但我仍然无法使用路径助手}}

/railsapp/app/assets/javascripts/components/GigSearchForm.js.jsx.erb:47:in `block in singleton class': undefined local variable or method `gigs_path' for #<#<Class:0x007f80bb0b1df8>:0x007f80bb1528e8> (NameError)

正如您所看到的,资产正在从ERB转换为JSX到JS,并且在处理ERB时无法找到路径助手gigs_path。我已经尝试过实施解决方案,比如包括像这样的初始化程序:

Rails.application.assets.context_class.class_eval do
  include ActionView::Helpers
  include Rails.application.routes.url_helpers
end
Sprockets::Context.send :include, Rails.application.routes.url_helpers
Sprockets::Context.send :include, ActionView::Helpers

在JSX文件的顶部,包括行:<% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %>

尽管如此,我仍然遇到类似的错误,即gigs_path以某种方式未定义。

0 个答案:

没有答案