Asset Pipeline in Active Model Serializers

active-model-serializers, asset-pipeline, ruby-on-rails, ruby-on-rails-4

Solution

Maybe this could work:

def post_image
  _helpers = ActionController::Base.helpers
  _helpers.image_url "posts/#{object.id}"
end

Problem

I'm attempting to include an image asset pipeline url in my model serializer output by including ActiveView::Helpers: ``` class PostSerializer < ActiveModel::Serializer include ActiveView::Helpers attributes :post_image def post_image image_path "posts/#{object.id}" end end ``` The result is `/images/posts/{id}` rather than a valid path to the asset pipeline path, ie. `/assets/images/posts/{id}`. How can I include valid asset pipeline paths in my serializer output?

Original source