18

I'm trying to use Sprockets' image_path method from within a Rails 3 model. I've tried including ActionView::Helpers::AssetTagHelper in my model and calling image_path but that does not work (undefined local variable or method 'config').

Any ideas?

Update - this worked for me:

ActionController::Base.new.view_context.asset_path("image.png")
SFnx
  • 203
  • 2
  • 8

1 Answers1

38

I think this is the standard way of loading the asset helper:

ActionController::Base.helpers.asset_path("image.png")

This seems preferable to creating a new instance of ActionController::Base and asking for the view context in that it is more explicit.

Abram
  • 39,950
  • 26
  • 134
  • 184
Alan H
  • 1,263
  • 1
  • 15
  • 21