Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access image_path route helper inside a Rails 3 model?

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")
like image 648
SFnx Avatar asked Nov 07 '12 00:11

SFnx


1 Answers

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.

like image 98
Alan H Avatar answered Nov 12 '22 08:11

Alan H