抛出此错误: Couldn't find Image with 'id'=create_institution Request parameters {"act-6ren">
gpt4 book ai didi

ruby-on-rails - 使用link_to时出现奇怪的Rails4错误

转载 作者:行者123 更新时间:2023-12-03 08:26:40 25 4
gpt4 key购买 nike

这行代码:

<%=link_to('Click for video.', image_path("create_institution.gif"), :target => "_blank")%>

抛出此错误:
Couldn't find Image with 'id'=create_institution

Request parameters
{"action"=>"show", "controller"=>"images", "id"=>"create_institution", "format"=>"gif"}

这是我的路线问题还是其他问题? "create_institution.gif"/assets/images中。我有一个“图像”模型,但在其他地方使用图像没有问题。

my routes.rb的Pastebin

最佳答案

在您的应用程序中,您将image作为资源,这就是为什么image_path解析为images#show的原因

根据image_path的文档,

If you have images as application resources this method may conflict with their named routes. The alias path_to_image is provided to avoid that. Rails uses the alias internally, and plugin authors are encouraged to do so.



因此,您可以使用 path_to_image解决此问题。
<%=link_to('Click for video.', path_to_image("create_institution.gif"), :target => "_blank")%>

希望这可以帮助!

关于ruby-on-rails - 使用link_to时出现奇怪的Rails4错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39197016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com