Rails link_to 问题

发布于 2024-11-18 12:45:08 字数 587 浏览 2 评论 0原文

我正在尝试构建一个链接。生成的链接应该如下所示:

http://localhost:3000/re_goal/edit/2

这就是我想出的:

<%= @issue.re_artifact_properties.collect { |properties| link_to properties.name, re_goal_path()}.to_sentence %>

它现在说我可能有不明确的路线。

content_url has the following required parameters: ["projects", :project_id, "re_goal", :id]

但是,如果我将 project_id 作为选项传递,则构建的链接看起来像这样:

http://localhost:3000/projects/1/re_goal/1

Doesany1 has a idea on how to 创建正确的链接?

谢谢,

尼科

I'm trying to construct a Link. The resulting Link should look something like this:

http://localhost:3000/re_goal/edit/2

This is what I came up with:

<%= @issue.re_artifact_properties.collect { |properties| link_to properties.name, re_goal_path()}.to_sentence %>

It now says that i may have ambiguous routes.

content_url has the following required parameters: ["projects", :project_id, "re_goal", :id]

But if i pass the project_id as an option, the constructed link looks something like this:

http://localhost:3000/projects/1/re_goal/1

Does any1 has an idea on how to construct the correct link?

Thanks,

Nico

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的他你的她 2024-11-25 12:45:08

看起来您已经在那里生成了一个嵌套路由。提供所需的参数,或删除嵌套路由。

或者选择浅层路线的“中间路线”:

resources :projects, :shallow => true do 
  resources :re_goal
end

Looks like you've got a nested route being generated there. Either supply the required params, or remove the nested route.

Or go for the 'middle way' of shallow routes:

resources :projects, :shallow => true do 
  resources :re_goal
end
傲鸠 2024-11-25 12:45:08

如果您有一个带有参数的路由,则必须提供它们。 rake paths 对于确定需要哪些参数以及应以什么顺序提供它们非常有用。您的路线可能如下所示:

projects/:project_id/re_goal/:id

在这种情况下,您需要提供 project_idid 作为 re_goal_path 的两个参数。如果省略它们,您会收到“必需参数”错误。从您的问题中不清楚您如何从 @issue 获得项目或目标,但这就是您所需要的。

If you have a route that takes parameters, you must supply them. rake routes can be useful for determining what arguments are required and what order they should be provided in. Your route probably looks like this:

projects/:project_id/re_goal/:id

In this case you will need to provide project_id and id as the two arguments to re_goal_path. If you omit them you get the "required parameters" error. It's not clear from your question how you get a project or a goal from your @issue, but that's what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文