ExecJS::RuntimeError in rails 3.2.8 engine with javascript_include_tag

帅比萌擦擦* 提交于 2019-12-13 02:43:20

问题


We are putting two rails 3.2.8 engines together in one rails app. The problem is that ExecJS does not like namespace for javascript_inclide_tag in layouts file. Here is the tag which causing the error:

<%= javascript_include_tag 'authentify/application' %>

Here authentify is rails engine name. The error is:

ExecJS::RuntimeError in Authentify/sessions#new 
Showing C:/D/code/rails_proj/engines/authentify/app/views/layouts/sessions.html.erb where line #6 raised: 

  (in C:/D/code/rails_proj/engines/authentify/app/assets/javascripts/authentify/sessions.js.coffee)
Extracted source (around line #6): 
3: <head>
4:   <title>Login</title>
5:   <%= stylesheet_link_tag    "authentify/application" %>
6:   <%= javascript_include_tag "authentify/application" %>
7:   <%= csrf_meta_tags %>
8: </head>
9: 

If we delete the namespace authentify (<%= javascript_include_tag "application" %>), then the ExecJS error disappears and the rails app works. There is the same error for another rails engine with the js tag.

We are using windows environment. What could cause the error? Thanks for the help.

UPDATE:

In engine.rb for authentify, every js libraries are listed as:

initializer "Authentify precompile hook", :group => :all do |app|
      app.config.assets.precompile += [
        'authentify/application.css.scss', 'authentify/layout.css.scss', 'authentify/login.css.scss', 
        'authentify/paginate.css.scss', 'authentify/sessions.css.scss', 'authentify/sys_logs.css.scss', 
        'authentify/toolbar.css.scss', 'authentify/user_level_group_map.css', 'authentify/user_menus.css.scss', 
        'authentify/users.css.scss', 'authentify/application.js', 'authentify/sessions.js.coffee', 
        'authentify/sys_logs.js.coffee', 'authentify/user_level_group_map.js', 'authentify/user_menus.js.coffee', 
        'authentify/users.js']

    end

回答1:


See this question: Using javascript_include_tag with a Subfolder full of JS

Can you have an initializer for each engine? In which case you could have:

Initializer for one (call it authentify) - e.g. authentify.rb as one initializer for engine A:

ActionView::Helpers::AssetTagHelper.register_javascript_expansion :authentify => Dir["#{Rails.root.to_s}/public/javascripts/authentify/*.js"].each {|js| js.gsub!("#{Rails.root.to_s}/public/javascripts/",'')}

Initializer for the other (call it authentify2) - e.g. authentify2.rb as one initializer for engine B:

ActionView::Helpers::AssetTagHelper.register_javascript_expansion :authentify2 => Dir["#{Rails.root.to_s}/public/javascripts/authentify2/*.js"].each {|js| js.gsub!("#{Rails.root.to_s}/public/javascripts/",'')}

and then you can have:

<%= javascript_include_tag :authentify %>

in one layout and:

<%= javascript_include_tag :authentify2 %>

in the other, and just remove the <%= javascript_include_tag 'authentify/application' %> in your layout as well as the other javascript_include_tag tag for your other engine.




回答2:


The issue is that execjs does not work on windows 8. Here is a post about how to go into the execjs runtimes and fix it on windows 8.



来源:https://stackoverflow.com/questions/13556699/execjsruntimeerror-in-rails-3-2-8-engine-with-javascript-include-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!