We are stuck trying to reference the image_path helper inside a serializer. We've tried including AssetTagHelper directly, but it chokes with an error:
undefined local variable or method `config' for #<GiftCardTypeSerializer:0x007fd9b6c84618>"
Digging into the AssetTagHelper, it seems coupled to a controller.
Is there any way to reference these assets safely? Generating my own URLs feels a bit barbaric. :)
Hmmm. I am not 100% sure at this moment, to be honest.
I'm having this issue as well, are there any solutions to this? I tried using view_context as suggested here:
http://stackoverflow.com/questions/5943188/how-can-i-use-image-path-inside-rails-3-controller
But that didn't work well for me.
I'm having the same problem :( I've included the Sprockets::Helpers::RailsHelper inside my serializer, but I get the same error than @mattgreen...
@mrcasals I got mine to work, try including these at the top of your serializer:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
include ActionView::Helpers::AssetTagHelper
Thanks for the update! /cc @morganick
@jonchay's tip worked for me :)
@jonchay thx :clap:
Giving this a close, then.
I had the same issue with Rails 4.1.1 and active_model_serializers 0.8.1. I solved it using ActionController::Base.helpers.asset_path as suggested here: http://stackoverflow.com/a/16609815.
Hope this helps :)
Most helpful comment
I had the same issue with Rails 4.1.1 and active_model_serializers 0.8.1. I solved it using
ActionController::Base.helpers.asset_pathas suggested here: http://stackoverflow.com/a/16609815.Hope this helps :)