rails/rails — Issue #3333: Asset pipeline is trying to compute public path of file contents
Author: HiroProt
Created: 2011-10-14 20:38:11+00:00
State: open

I just upgraded from 3.1 to 3.1.1, and am running into issues with the asset pipeline. I get the following error:

```
File name too long - /Users/maym/Projects/forkly/app/assets/images/Backbone.RailsJSON = {
// In order to properly wrap/unwrap Rails JSON data, we need to specify
// what key the object will be wrapped with.
_name : function() {
if (!this.name) throw new Error("A 'name' property must be specified");
return this.name;
},
{...}
```

Partial Stack trace:

```
/Users/maym/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:963:in `open'
/Users/maym/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:963:in `entries'
/Users/maym/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:963:in `entries'
hike (1.2.1) lib/hike/index.rb:80:in `entries'
hike (1.2.1) lib/hike/index.rb:129:in `match'
hike (1.2.1) lib/hike/index.rb:113:in `block in find_in_paths'
hike (1.2.1) lib/hike/index.rb:112:in `each'
hike (1.2.1) lib/hike/index.rb:112:in `find_in_paths'
hike (1.2.1) lib/hike/index.rb:63:in `block in find'
hike (1.2.1) lib/hike/index.rb:57:in `each'
hike (1.2.1) lib/hike/index.rb:57:in `find'
sprockets (2.0.2) lib/sprockets/trail.rb:74:in `resolve'
sprockets (2.0.2) lib/sprockets/trail.rb:78:in `resolve'
sprockets (2.0.2) lib/sprockets/trail.rb:96:in `find_asset_in_path'
sprockets (2.0.2) lib/sprockets/base.rb:101:in `find_asset'
sprockets (2.0.2) lib/sprockets/index.rb:48:in `find_asset'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:141:in `digest_for'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:154:in `rewrite_asset_path'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb:64:in `path_to_asset'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb:19:in `asset_tag'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb:57:in `block in include_tag'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb:57:in `collect'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb:57:in `include_tag'
actionpack (3.1.1) lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb:187:in `javascript_include_tag'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:29:in `block (2 levels) in javascript_include_tag'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:28:in `map'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:28:in `block in javascript_include_tag'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:26:in `collect'
actionpack (3.1.1) lib/sprockets/helpers/rails_helper.rb:26:in `javascript_include_tag'
```

Upon digging a little deeper, and inserting this code:

```ruby
module ActionView
class AssetPaths
def compute_public_path(source, dir, options = {})
Rails.logger.debug("COMPUTING PUBLIC PATH: #{source}|||#{dir}|||#{options}")
source = source.to_s
return source if is_uri?(source)

source = rewrite_extension(source, dir, options[:ext]) if options[:ext]
source = rewrite_asset_path(source, dir, options)
source = rewrite_relative_url_root(source, relative_url_root)
source = rewrite_host_and_protocol(source, options[:protocol])
source
end
end
end

module Sprockets
class Base
def [](*args)
Rails.logger.debug("NOW FINDING #{args}")
find_asset(*args)
end
end
end
```

I can see that Rails is trying to find/compute the public path of the actual file contents of the my JS/CSS files in addition to their proper filenames.

Output excerpt:

```
COMPUTING PUBLIC PATH: jquery.js|||/assets|||{:ext=>"js", :body=>true, :digest=>true}
NOW FINDING ["jquery.js"]
COMPUTING PUBLIC PATH: /*!
* jQuery JavaScript Library v1.6.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
* http://sizzlejs.com/
* Copyright 2011, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Thu Jun 30 14:16:56 2011 -0400
*/

(function( window, undefined ) {

// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
navigator = window.navigator,
location = window.location;
{..}
```

This seems to be a major issue, but I have no idea what's causing it. Any ideas?