nex3/haml — Issue #467: image-url helper raises an exception when used inline
Author: awd-switzerland
Created: 2011-12-05 10:03:38+00:00
State: open

This issue was first opened as a sass bug: https://github.com/nex3/sass/issues/201
Upon nex3 stating this was a sass-rails bug instead, it was moved on to sass-rails: https://github.com/rails/sass-rails/issues/68
Where chriseppstein claimed this was a haml bug. So here we are…

The following snipped in _some_partial.haml fails reproducably with sass 3.1.10, rails 3.1.1 and ruby 1.9.2p290:

%style(type="text/css")
:sass
#whatever
background-image: image-url('some/asset.png')

If you put the exact same piece of sass into an external sass file, no exception is raised.

The exception we get is:

NoMethodError
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

Backtrace (up to the entry point from actionpack, we can provide the rest too if necessary):

sass-rails (3.1.4) lib/sass/rails/helpers.rb:40:in `resolver'
sass-rails (3.1.4) lib/sass/rails/helpers.rb:25:in `image_url'
sass (3.1.10) lib/sass/script/funcall.rb:88:in `_perform'
sass (3.1.10) lib/sass/script/node.rb:40:in `perform'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:214:in `visit_prop'
sass (3.1.10) lib/sass/tree/visitors/base.rb:37:in `visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:18:in `visit'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `map'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `visit_children'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:27:in `block in visit_children'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:39:in `with_environment'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:26:in `visit_children'
sass (3.1.10) lib/sass/tree/visitors/base.rb:37:in `block in visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:234:in `visit_rule'
sass (3.1.10) lib/sass/tree/visitors/base.rb:37:in `visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:18:in `visit'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `map'
sass (3.1.10) lib/sass/tree/visitors/base.rb:53:in `visit_children'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:27:in `block in visit_children'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:39:in `with_environment'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:26:in `visit_children'
sass (3.1.10) lib/sass/tree/visitors/base.rb:37:in `block in visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:47:in `visit_root'
sass (3.1.10) lib/sass/tree/visitors/base.rb:37:in `visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:18:in `visit'
sass (3.1.10) lib/sass/tree/visitors/perform.rb:7:in `visit'
sass (3.1.10) lib/sass/tree/root_node.rb:20:in `render'
sass (3.1.10) lib/sass/engine.rb:300:in `_render'
sass (3.1.10) lib/sass/engine.rb:248:in `block in render'
sass (3.1.10) lib/sass/util.rb:297:in `silence_sass_warnings'
sass (3.1.10) lib/sass/engine.rb:248:in `render'
haml (3.1.3) lib/haml/filters.rb:311:in `render'
haml (3.1.3) lib/haml/filters.rb:71:in `render_with_options'
haml (3.1.3) lib/haml/filters.rb:121:in `block in compile'
haml (3.1.3) lib/haml/filters.rb:99:in `instance_eval'
haml (3.1.3) lib/haml/filters.rb:99:in `compile'
haml (3.1.3) lib/haml/filters.rb:80:in `internal_compile'
haml (3.1.3) lib/haml/compiler.rb:210:in `compile_filter'
haml (3.1.3) lib/haml/compiler.rb:447:in `compile'
haml (3.1.3) lib/haml/compiler.rb:446:in `block (2 levels) in compile'
haml (3.1.3) lib/haml/compiler.rb:446:in `each'
haml (3.1.3) lib/haml/compiler.rb:446:in `block in compile'
haml (3.1.3) lib/haml/compiler.rb:170:in `compile_tag'
haml (3.1.3) lib/haml/compiler.rb:447:in `compile'
haml (3.1.3) lib/haml/compiler.rb:446:in `block (2 levels) in compile'
haml (3.1.3) lib/haml/compiler.rb:446:in `each'
haml (3.1.3) lib/haml/compiler.rb:446:in `block in compile'
haml (3.1.3) lib/haml/compiler.rb:48:in `compile_root'
haml (3.1.3) lib/haml/compiler.rb:447:in `compile'
haml (3.1.3) lib/haml/engine.rb:124:in `initialize'
haml (3.1.3) lib/haml/template/plugin.rb:34:in `new'
haml (3.1.3) lib/haml/template/plugin.rb:34:in `compile'
haml (3.1.3) lib/haml/template/plugin.rb:39:in `call'
actionpack (3.1.1) lib/action_view/template.rb:253:in `compile'

Thanks for having a look at it.

For the fellow reader who has the same issue, joevandyk suggested a workaround:
background-url: '#{ image_path('email/logo-high-res.png') }'