Вопрос

I've decided to use javascript_inlcude_tag 'google_analytics.js' in my templates, avoiding many of the gems that would get it done for me in favor of testing the new Google Analytics "Universal" features.

Thing is that Google Analytics provided code is not in Coffeescript, and so I add it to my vendor/assets/javascripts just like I've done with many other libraries used in my App. But unlike all the others, the javascript_include_tag approach is causing Rails to halt on the error:

Rails ActionView::Template::Error (google_analytics.js isn't precompiled)

The other vendor libraries are just being 'required', inside many of my Coofeescripts.

Does anybody know what is wrong with this current analytics javascript approach?

Это было полезно?

Решение

Likewise suggested by Dan McClain in this (related) post, the issue was solved by adding the following line in config/environments/production.rb:

config.assets.precompile += %w( google_analytics.js )

Done!

Другие советы

A previous comment:

Google Analytics provided code is not in Coffeescript, and so I add it to my vendor...

It is not necessary for the js to be in Coffeescript to be either included in your assets pipeline through a direct //= require google_analytics in application.js, being the extension of the file .js.coffee or just .js.

Said that and assuming that you are getting that error in the production environment it seems that you are not adding your js file to the assets precompile array. In your config/environments/production.rb the following line is needed:

config.assets.precompile += %w( google_analytics.js )

Hope that helps

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top