本文介绍了带有javascript_include_tag的Rails 3.2.8引擎中的ExecJS :: RuntimeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在一个rails应用程序中将两个rails 3.2.8引擎放在一起.问题在于ExecJS不喜欢布局文件中javascript_inclide_tag的名称空间.这是导致错误的标记:

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' %>

在这里验证的是Rails引擎名称.错误是:

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: 

如果我们删除命名空间authentify(<%= javascript_include_tag "application" %>),则ExecJS错误消失并且rails应用程序正常运行.另一个带有js标签的Rails引擎也存在相同的错误.

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.

我们正在使用Windows环境.是什么导致错误?谢谢您的帮助.

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

更新:

在engine.rb进行身份验证时,每个js库都列为:

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

推荐答案

看到此问题:

每个引擎都可以有一个初始化程序吗?在这种情况下,您可以:

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

一个的初始化程序(称为authentify)-例如authentify.rb作为引擎A的一个初始化程序:

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/",'')}

另一个的初始化程序(称为authentify2)-例如authentify2.rb作为引擎B的一个初始化程序:

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/",'')}

然后您可以:

<%= javascript_include_tag :authentify %>

采用一种布局,并且:

<%= javascript_include_tag :authentify2 %>

,只需删除布局中的<%= javascript_include_tag 'authentify/application' %>以及其他引擎的其他javascript_include_tag标签.

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.

这篇关于带有javascript_include_tag的Rails 3.2.8引擎中的ExecJS :: RuntimeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 10:35