简体   繁体   中英

Rails 4 asset pipeline: config.assets.precompile & conditional javascript

I'm using an script to detect internet explorer and display a message. It is not referenced in application.js and I don't want to have it there because it is for one specific page of a controller.

Following this article (§3) http://blog.55minutes.com/2012/02/untangling-the-rails-asset-pipeline-part-3-configuration/ , I added in my config/development.rb file the following:

config.assets.precompile += ['iealert.js']

Now in my application layout, at the bottom, I have (using haml)

/ [if IE]
      = javascript_include_tag "iealert"

The script is included in 2 places, at the bottom, but also in the header (with javascript_include_tag "application", "data-turbolinks-track" => true), therefore all browsers get the alert since the header inclusion is automatic and not conditional.

What am I doing wrong ?

Maybe something like this:

<%= javascript_include_tag :defaults %>
<!--[if IE]><%= javascript_include_tag "excanvas.min" %><![endif]-->

Rails 3 Conditional Inclusion of Javascript files

Could be wrong though :)

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