Skip to content

Can't use image-url in sass in actionmailer views #71

@joevandyk

Description

@joevandyk

The following is my actionmailer view:

:sass
  body
    background-url: image-url('rails.png')

Running that gives me this backtrace:

ActionView::Template::Error: 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.[]
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-rails-3.1.5/lib/sass/rails/helpers.rb:40:in `resolver'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-rails-3.1.5/lib/sass/rails/helpers.rb:25:in `image_url'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/script/funcall.rb:88:in `_perform'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/script/node.rb:40:in `perform'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:214:in `visit_prop'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:37:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:18:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `map'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:27:in `block in visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:39:in `with_environment'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:26:in `visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:37:in `block in visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:234:in `visit_rule'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:37:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:18:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `map'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:53:in `visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:27:in `block in visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:39:in `with_environment'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:26:in `visit_children'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:37:in `block in visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:47:in `visit_root'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/base.rb:37:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:18:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/visitors/perform.rb:7:in `visit'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/tree/root_node.rb:20:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/engine.rb:300:in `_render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/engine.rb:248:in `block in render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/util.rb:297:in `silence_sass_warnings'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sass-3.1.10/lib/sass/engine.rb:248:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:311:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:71:in `render_with_options'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:121:in `block in compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:99:in `instance_eval'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:99:in `compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/filters.rb:80:in `internal_compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:210:in `compile_filter'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:447:in `compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:446:in `block (2 levels) in compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:446:in `each'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:446:in `block in compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:48:in `compile_root'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/compiler.rb:447:in `compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/engine.rb:124:in `initialize'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/template/plugin.rb:34:in `new'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/template/plugin.rb:34:in `compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/haml-3.1.3/lib/haml/template/plugin.rb:39:in `call'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/template.rb:280:in `compile'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/template.rb:217:in `compile!'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/template.rb:170:in `block in render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/notifications.rb:55:in `instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/template.rb:169:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:40:in `block (2 levels) in render_template'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/notifications.rb:53:in `block in instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/notifications.rb:53:in `instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:39:in `block in render_template'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:38:in `render_template'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:12:in `block in render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/abstract_renderer.rb:17:in `wrap_formats'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/template_renderer.rb:9:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/renderer.rb:36:in `render_template'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/action_view/renderer/renderer.rb:17:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/abstract_controller/rendering.rb:120:in `_render_template'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/abstract_controller/rendering.rb:114:in `render_to_body'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.2/lib/abstract_controller/rendering.rb:99:in `render'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/old_api.rb:206:in `block in create_parts'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/old_api.rb:204:in `each'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/old_api.rb:204:in `create_parts'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/old_api.rb:67:in `process'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/base.rb:474:in `process'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/base.rb:469:in `initialize'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/base.rb:456:in `new'
    /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.2/lib/action_mailer/base.rb:456:in `method_missing'
    test/functional/mailer_test.rb:9:in `block in <class:MailerTest>'

I setup a sample rails 3.1.2 application that shows this bug.

(I was also testing the other ways to include URLs in emails)

Run 'rake' to run the tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions