Remus Rusanu
Remus Rusanu

Reputation: 294237

javascript_include_tag "directory/file" results in incorrect path for //= require assets

I want to use //= require <lib> from a different file than /app/assets/javascripts/application.js. This results in a asset compile error but the problem is that the path is incorrect. I made a simplified project that show the problem available at https://github.com/rusanu/test-ember.

In the layout:

<head>
  <title>TestEmber</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= yield :head %>
  <%= csrf_meta_tags %>
</head>

In the view:

<%= content_for :head do %>
<%= javascript_include_tag "dashboard/dashboard", :cache => 'dashboard' %>
<% end %>

and in my dashboard/dashboard.js:

//= require handlebars
//= require ember
//= require ember-data
//= require_self

This results in error:

Showing /home/rremus/test-ember/app/views/dashboard/show.html.erb where line #2 raised:

No such file or directory - Asset file not found at '/home/rremus/test-ember/public/home/rremus/.rvm/gems/ruby-2.0.0-p0/gems/handlebars-source-1.0.0.rc4/dist/handlebars.js'
Extracted source (around line #2):

1: <%= content_for :head do %>
2: <%= javascript_include_tag "dashboard", :cache => 'dashboard' %>
3: <% end %>
4: 
5: <h1>Dashboard#show</h1>

Notice how the asset path consist of the project public directory (/home/rremus/test-ember/public) and then correct asset path (/home/rremus/.rvm/...) is appended, resulting into an incorrect path.

Upvotes: 1

Views: 1731

Answers (1)

Matt Glover
Matt Glover

Reputation: 1347

My guess is that you have to do some special gymnastics to get it working with the cache directive in this case based on the Rails guide for the asset pipeline.

If you ditch the cache directive and rely on precompilation to handle file combination then things seem to work without error.

Upvotes: 2

Related Questions