I have this code:
class ExampleController < ApplicationController
include ActionView::Helpers::AssetUrlHelper
def show
respond_to do |format|
msg = { status: "ok", message: "Success!", image_url: image_url('image.png') }
format.json { render :json => msg }
end
end
end
This return me this response:
{ status: "ok", message: "Success!", image_url: 'images/image.png' }
And I expect something like:
{ status: "ok", message: "Success!", image_url: 'assets/image-37bf76be1.png' }
What is the problem?
I believe you need to use view_context.image_url
if you want to render an image from the controller.