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")
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With