Tuesday 15 September 2015

javascript - erb in coffeescript (Rails 3.2.13)? -


I am using Rail 3.2.13.

After looking at some posts here, it seems that in order to use ARB in the coffee script, your file needs a .js.coffee extension, .js.coffee.erb is not (weird).

However, I still can not seem to work for it. For example, I have the following in the demo.js.coffee file:

  console.log '& lt;% = root_url% & gt;   

After all the processing, it starts producing:

  (function () {console.log ('& lt;% = root_url% Gt; '); $ (function () {});}). Call (this);   

As you can see, the coffee script is processed, but not the ARB. What is happening?

In some cases the .erb extension is required and in some cases it is not . I have found that even when it is necessary to deal with the coffee script files under the asset directory, even when it is contained within the ideas

then in your case it demo.js.coffee The second problem is that ARB is being evaluated outside the app, you need the following lines:

  '& lt;% url = Rail Web Application: Name: application.routes.url_helpers% & gt; Console.log '& lt;% = url.root_path% & gt;   

A similar question can be found here

No comments:

Post a Comment