Is there any way to use a Rails helper method, more specifically, a path helper method within a javascript asset file. This file foo.js.coffee.erb
Indeed I agree with @eirc answer (taking into account Sprockets documentation). But I would consider including helper modules at rails boot time. As per
# config/initializers/sprockets.rb
Rails.application.assets.context_class.instance_eval do
include ActionView::Helpers
include Rails.application.routes.url_helpers
include MyModule
end
this is because of: https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L23