[英]Rails 4.2 image_path with different url for controller
I'm using image_path into my controller: 我正在使用image_path进入我的控制器:
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'}
. 但我的回报是{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. 当我在我的视图中使用image_path('docs/pdf.png')
时,网址为'/docs/pdf.png'并且有效。
Why in my controller the url is different? 为什么在我的控制器中网址不同?
Answer from my comment: 我的评论回答:
You can use view_context.image_path 'pdf.png'
without including the helper library. 您可以使用view_context.image_path 'pdf.png'
而不包括帮助程序库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.