문제

How can I render javascript files containing ruby code (<%= ... %>) using Jammit? Jammit gem will always read JS files and will not evaluate the ruby code. Solutions? Thx!

도움이 되었습니까?

해결책

I couldn't find a plugin so I wrote one: https://github.com/xpepermint/js_erb

다른 팁

erb stands for "embedded ruby", and has nothing to do with html. There is nothing stopping you from making a js.erb view, with a route pointing to it. Unfortunately, you can't bundle it with jammit, since that would defeat the purpose of having it as a dynamic view.

One of the main use of an asset packager is for caching all the JS/CSS in one file. Even if Jammit or another packager was able to evaluate some Ruby code inside these files, it will be evaluated only once during the application startup, thus it would be totally useless!

It is not a great idea to put Ruby evaluated code in JS, there is always a good workaround.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top