Rails ERB Rails routing method not found in active JSX

I am collecting some JSX assets as part of my Rails 4 application using ReactJS (using gem ), and I cannot use route helpers despite including them according to these answers .

/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)

As you can see, the asset is transformed from ERB to JSX in JS, and gigs_pathno helper was found during ERB processing . I already tried to implement such solutions as enabling an initializer:

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

And at the top of the JSX file, including the line: <% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %>

However, I keep getting a similar error that gigs_path is undefined somehow.

+4

Source: https://habr.com/ru/post/1570935/


All Articles