Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么可以';我不能在演示者中使用图像url吗?_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 为什么可以';我不能在演示者中使用图像url吗?

Ruby on rails 为什么可以';我不能在演示者中使用图像url吗?,ruby-on-rails,ruby,Ruby On Rails,Ruby,当我从我的助手运行image_url时,它会工作。 当我尝试从演示者文件运行同一行时,它会显示NoMethodError for image\u url module Presenters class PaymentMethod ... def logo image_url("logo.svg") end end end 我想知道为什么会发生这种情况,以及如何更改它,以便在演示者中使用这种方法 image\u url来自ActionView::H

当我从我的助手运行image_url时,它会工作。 当我尝试从演示者文件运行同一行时,它会显示NoMethodError for image\u url

module Presenters
  class PaymentMethod
    ...


    def logo
      image_url("logo.svg")
    end
  end
end

我想知道为什么会发生这种情况,以及如何更改它,以便在演示者中使用这种方法

image\u url
来自
ActionView::Helpers
模块

您应该首先包括
ActionView::Helpers
模块,然后使用
image\u url
方法

module Presenters
  class PaymentMethod
    include ActionView::Helpers


    def logo
      image_url("logo.svg")
    end
  end
end

现在,image_url返回:“而不是:”您可以通过链接
localhost:3000/assets/visa logo.svg
查看图像吗?如果rails找不到该图像,它将返回到
/images/visa logo.svg
。是的,我可以看到它,当该方法在帮助程序中时,它会工作。