简体   繁体   中英

javascript_tag and <script> tag are being stripped from erb templates

I am a Ruby/Rails noob and have just started working on a legacy Rails app that's running on Passenger using ree-1.8.7.

My issue is that every time I add javascript_tag calls or tags to some .erb templates, they always get stripped out of the final output when the page renders in browser, but only on some of the views, not all. I am trying to find where that setting may be configured, but can't find anything.

The templates are in subdirectories of app/views, both ones that work and ones that don't work.

For example, if I put a simple snipped like this

<%= javascript_tag "
    var test='test'
" %>

in the browser page source i never see generated javascript where as if i put it in "good" erb files, it is seen.

Your file may be named incorrectly. show.html.erb right? What version of rails too?

I finally figured this out. This was due to PrototypeJS making Ajax calls, and by default they strip javascript tags in the response. More on this here:

https://groups.google.com/d/msg/prototype-scriptaculous/ox5KB9rJ8cc/IzXqd4eOWRgJ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM