Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers not available in assets:precompile #19

Closed
adamburmister opened this issue Jan 19, 2012 · 3 comments
Closed

Helpers not available in assets:precompile #19

adamburmister opened this issue Jan 19, 2012 · 3 comments

Comments

@adamburmister
Copy link

I have found that I am getting an error when running assets:precompile stating the helpers are not available.

error evaluating function image-url``

Everything runs fine in development mode with dynamic compilation of stylesheets, but not on precompile. Any suggestions as to why they are not available?

rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
error evaluating function `image-url`
  (in /Users/adam/Development/backchat-marketing/app/assets/stylesheets/homepage.css.less)
at /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/js/lib/less/parser.js:336:38
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:88:in `block in to_css'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:13:in `block in calljs'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:27:in `block in lock'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:25:in `lock'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:12:in `calljs'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-2.0.8/lib/less/parser.rb:87:in `to_css'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-rails-2.1.2/lib/less/rails/template_handlers.rb:17:in `evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:175:in `block in evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:172:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:172:in `evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:171:in `build_dependency_context_and_body'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:135:in `dependency_context'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:194:in `build_dependencies_paths_and_assets'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:141:in `dependency_paths'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:61:in `mtime'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:58:in `block in encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:57:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:57:in `encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:43:in `encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/caching.rb:52:in `cache_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:67:in `block in build_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:76:in `memoize'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:65:in `build_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/trail.rb:102:in `find_asset_in_path'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:101:in `find_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:48:in `find_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:110:in `[]'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-rails-2.1.2/lib/less/rails/import_processor.rb:13:in `block in evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-rails-2.1.2/lib/less/rails/import_processor.rb:12:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/less-rails-2.1.2/lib/less/rails/import_processor.rb:12:in `evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:175:in `block in evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:172:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/context.rb:172:in `evaluate'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:171:in `build_dependency_context_and_body'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:135:in `dependency_context'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:194:in `build_dependencies_paths_and_assets'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:141:in `dependency_paths'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:61:in `mtime'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:58:in `block in encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:57:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/asset.rb:57:in `encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/bundled_asset.rb:43:in `encode_with'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/caching.rb:52:in `cache_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:67:in `block in build_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:76:in `memoize'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:65:in `build_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/trail.rb:102:in `find_asset_in_path'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:101:in `find_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/index.rb:48:in `find_asset'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/static_compiler.rb:20:in `block in compile'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:151:in `block in each_logical_path'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:139:in `block (2 levels) in each_file'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:129:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:129:in `each_entry'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:137:in `block in each_file'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:136:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:136:in `each_file'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.3/lib/sprockets/base.rb:149:in `each_logical_path'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/static_compiler.rb:18:in `compile'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:52:in `internal_precompile'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:66:in `block (3 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile:primary
rake aborted!
Command failed with status (1): [/Users/adam/.rvm/rubies/ruby-1.9.2-p290/bi...]
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `ruby'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
@adamburmister
Copy link
Author

I'm opening up the gem and trying to debug the issue: for your reference this is the parser options hash being generated:

{:filename=>"/Users/adam/Development/backchatio-marketing/app/assets/stylesheets/homepage.css.less", :line=>1, :paths=>["/Users/adam/Development/backchatio-marketing/app/assets/stylesheets", "/Users/adam/Development/backchatio-marketing/vendor/assets/stylesheets", "/Users/adam/.rvm/gems/ruby-1.9.2-p180/gems/less-rails-bootstrap-1.4.2/vendor/assets/stylesheets", "/Users/adam/.rvm/gems/ruby-1.9.2-p180/gems/less-rails-bootstrap-1.4.2/vendor/frameworks", "/Users/adam/Development/backchatio-marketing/app/assets/fonts", "/Users/adam/Development/backchatio-marketing/app/assets/images", "/Users/adam/Development/backchatio-marketing/app/assets/javascripts", "/Users/adam/Development/backchatio-marketing/app/assets/stylesheets", "/Users/adam/Development/backchatio-marketing/vendor/assets/stylesheets", "/Users/adam/.rvm/gems/ruby-1.9.2-p180/gems/jquery-rails-1.0.19/vendor/assets/javascripts", "/Users/adam/.rvm/gems/ruby-1.9.2-p180/gems/less-rails-bootstrap-1.4.2/vendor/assets/javascripts", "/Users/adam/.rvm/gems/ruby-1.9.2-p180/gems/less-rails-bootstrap-1.4.2/vendor/assets/stylesheets"]}

Opening the parser.js file and dumping out the tree.functions object's keys I find the following, which indicates they are there and available for use:

rgb,rgba,hsl,hsla,hue,saturation,lightness,alpha,saturate,desaturate,lighten,darken,fadein,fadeout,fade,spin,mix,greyscale,e,escape,%,round,argb,asset-path,asset-url,image-path,image-url,video-path,video-url,audio-path,audio-url,javascript-path,javascript-url,stylesheet-path,stylesheet-url,font-path,font-url,asset-data-url

@adamburmister
Copy link
Author

I have drilled down to the Less-2.0.8 gem, into call.js to debug the try/catch there.

The resulting exception message is:
Error: This asset host cannot be computed without a request in scope. Remove the second argument to your asset_host Proc if you do not need the request.

@adamburmister
Copy link
Author

The cause of the problem was the setting of asset_host to a Proc within rails. The aim of this was to switch HTTP/HTTPS on the CDN we use. This may be a common issue for others.

The cause:

config.action_controller.asset_host = Proc.new do |source, request|
    method = request.ssl? ? "https" : "http"
    "#{method}://foobar.cloudfront.net"
end

The solution:
Remove the CDN switch, or guard against the missing request argument.

config.action_controller.asset_host = Proc.new do |source, request=nil|
    method = request != nil && request.ssl? ? "https" : "http"
    "#{method}://foobar.cloudfront.net"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant