3

I'm using Rails 3.2.8. When the app is deployed access the view that is including a javascript:

<%= javascript_include_tag "epiceditor" %>

Heroku fails with this log:

ActionView::Template::Error (/app/app/assets/javascripts/epiceditor.js.erb has already been required

I've checked some possible solutions, like checking for any reference that may trigger a circular dependency, or simply removing it in case it is being included somewhere else, which isn't. So, if I include it, I get this "has already been included error", if I don't , then the file isn't included at all.

My config/application.rg has this

    config.assets.initialize_on_precompile = false

And applications.js has this:

//= require jquery
//= require jquery_ujs
//= require tabs

It might be important to note that the file the tag is referencing is "epiceditor.js.erb", since it has some embedded Rails code that I needed.

Thanks for your help

EDIT:

I believe this is a bug in Sprockets. If I update Rails to 3.2.9rc2, the error is now this: ActionView::Template::Error (Asset logical path has no extension: epiceditor/.js

but of course the extension in epiceditor is epiceditor.js.erb, and I've tried being explicit about it in the javascript_include_tag as well.

6
  • You say Heroku fails; I take it it works in development? Commented Dec 2, 2012 at 23:17
  • Yes, it does work in development environment. Is at Heroku production that fails. Commented Dec 2, 2012 at 23:19
  • Just to be sure, when you say it's working in development, is the file being included in your HTML, or is the page just loading without error? Seeing what you have in your application.js file, the epiceditor.js.erb file won't be loaded unless you specifically call it: require epiceditor, or unless you're loading in the rest of the files in the folder with: require tree ., (I think that's the right syntax - I've just written that from memory). Commented Dec 3, 2012 at 7:32
  • I'm explicitly including it via <%= javascript_include_tag "epiceditor" %> in the necessary page, and indeed does it in development environment. If I use require_tree . it also works, but again, only in development. Commented Dec 3, 2012 at 8:41
  • Are you sure you are not, doing //= require_tree in the application.js? Commented Dec 3, 2012 at 13:26

1 Answer 1

3

I found the bug. It turns out that inside the .js.erb file I'm calling

<% asset_path 'epiceditor/' %>

which should expand to the path where all the epiceditor file are placed, but instead is actually loading the file itself in recursive manner. This is expanding properly in the development environment but not in the production environment. Funny, right? The reason for this is that is adding a digest. So I fixed the whole issue with this:

<%= asset_path 'epiceditor/', :digest => false %>

and now it does expand to the directory, and doesn't fall into the recursion trap.

Hope this saves some time for someone!

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

Comments

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.