How do I get escape_javascript and other helpers in my sprockets pre-processed js file (not a view)?
问题 I'm using Rails 3.1 and the sprockets stuff. I want to use ERB to pre-process a js file that will then be included using javascript_include_tag. It is generated from code, and so I'm pre-processing it with ERB, but I can't get to the helpers like escape_javascript from ActionView::Helpers::JavaScriptHelper Say my file is called dynamic.js.erb, and it contains obj = { name: "test", tag: "<%= escape_javascript( image_tag( "logo.png" ) )%>" }; How do I stop it from producing the error: throw