Rails 4.2 image_path with different url for controller

I am using image_path in my controller:

class ArchivesController < ApplicationController
    include ActionView::Helpers::AssetUrlHelper

    def create
        @archive = Archive.new(file: params[:file])

        render json: {ico: image_path('docs/pdf.png')}
    end
end

      

But my return {ico: '/images/docs/pdf.png'}

.

When I use image_path('docs/pdf.png')

in my views the url is "/docs/pdf.png" and it works.

Why is the url different in my controller?

+3


source to share


1 answer


Answer from my comment:



You can use view_context.image_path 'pdf.png'

without including the helper library.

+6


source







All Articles