gpt4 book ai didi

ruby-on-rails - 链接到 ruby​​ 中的表单

转载 作者:太空宇宙 更新时间:2023-11-03 17:59:20 24 4
gpt4 key购买 nike

我想使用函数链接指向一个表单。即 <%= link_to 'Reports', '/reports/index.html.erb' %>但这给了我一个错误,说没有路由匹配 '/reports/index.html.erb.

谢谢,拉姆亚。

最佳答案

Rails 不喜欢在 URL 中包含文档格式,除非有必要(比如当一个操作可以处理多种请求格式时)。如果您有 reports/index.html.erb,到它的路径将类似于以下之一:

match 'reports' => 'reports#index' #=> 'yourdomain.com/reports'
match 'reports/index' => 'reports#index' #=> 'yourdomain.com/reports/index

那么您的链接将是:

<%= link_to 'Reports', 'reports' %>

<%= link_to 'Reports', 'reports/index' %>

如果你真的想要.html,你可能会这样做:

match 'reports/index.html' => 'reports#index' #=> 'yourdomain.com/reports/index.html

match 'reports/index.:format' => 'reports#index' #=> 'yourdomain.com/reports/index.html

但是 .html 在第一种情况下是没有意义的,在第二种情况下是不必要的。我不建议这样做,因为这不是标准的 Rails 做法。

强烈推荐您阅读this tutorial on Routing ,至少前几节,然后再继续。它是 Rails 绝对重要的组成部分,如果您不了解它的工作原理,您将永远无法成为高效的 Rails 程序员。

关于ruby-on-rails - 链接到 ruby​​ 中的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7737535/

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