0

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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Just updated the post with initializer in engine.rb. Do you mean two initializers for engine authentify? Also can you explain more about your answer? We don't know much about the js tag other than including js libraries. Thanks for the help.
Edited - is this clearer? Not sure how you are running your 2 rails engines in parallel, they must be picking up config from somewhere? If so, put 1 initializer rb file under one config and the other initializer rb file under the other config.
We just mount two rails engine in one rails app. Thanks.
created js_init.rb under engine authentify's config/initializers with the line above and it worked. Can you explain why removing the partial js path solves the problem? Thanks.
1

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.

1 Comment

Thanks, this link led me to the right place. pottsk's workaround did the trick for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.