Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use image_path in serializer #193

Closed
mattgreen opened this issue Jan 21, 2013 · 9 comments
Closed

Unable to use image_path in serializer #193

mattgreen opened this issue Jan 21, 2013 · 9 comments

Comments

@mattgreen
Copy link

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. :)

@steveklabnik
Copy link
Contributor

Hmmm. I am not 100% sure at this moment, to be honest.

@jonchay
Copy link

jonchay commented Jan 24, 2013

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.

@mrcasals
Copy link

I'm having the same problem :( I've included the Sprockets::Helpers::RailsHelper inside my serializer, but I get the same error than @mattgreen...

@jonchay
Copy link

jonchay commented Feb 20, 2013

@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

@mattgreen
Copy link
Author

Thanks for the update! /cc @morganick

@mrcasals
Copy link

@jonchay's tip worked for me :)

@morganick
Copy link

@jonchay thx 👏

@steveklabnik
Copy link
Contributor

Giving this a close, then.

@pguegan
Copy link

pguegan commented Jun 23, 2014

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants