Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.2 image_path with different url for controller

I'm using image_path into 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 is {ico: '/images/docs/pdf.png'}.

When I'm use image_path('docs/pdf.png') in my views, the url is '/docs/pdf.png' and works.

Why in my controller the url is different?

like image 996
Bruno Mucelini Mergen Avatar asked Dec 12 '25 23:12

Bruno Mucelini Mergen


1 Answers

Answer from my comment:

You can use view_context.image_path 'pdf.png' without including the helper library.

like image 89
vich Avatar answered Dec 15 '25 14:12

vich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!