提交的 select_tag 需要重定向到显示带有 :id 的页面?

发布于 2024-10-07 06:02:32 字数 635 浏览 0 评论 0原文

你好 我之前问过类似的问题,但一直没有解决。所以我再次尝试。

这看起来应该是这么简单。顺便说一句,我还没有使用 Rails 3。

我想要做的就是有一个下拉菜单,当一个人选择该位置并按“转到”时,他们就会转到该页面。

    <% form_tag installation_path([:id]), :url => { :action => "show" }, :method => :get do %>
<%= select_tag :id, options_from_collection_for_select(Installation.find(:all), :id, :name) %>
<%= submit_tag 'Go' %>
<% end %>

这成为问题: http://localhost:3000/installations/id?id= 1&commit=创建。它找不到 :id。我只是不知道如何正确路由。看来这件事应该没有那么困难。

任何帮助都会很棒。谢谢。

Hi
I have asked a question similar to this before but never got it resolved. So I am trying again.

This seems like it should be so simple. I am not using Rails 3 yet BTW.

All I want to do is have a drop down menu and when a person chooses that location and presses "go" they go to that page.

    <% form_tag installation_path([:id]), :url => { :action => "show" }, :method => :get do %>
<%= select_tag :id, options_from_collection_for_select(Installation.find(:all), :id, :name) %>
<%= submit_tag 'Go' %>
<% end %>

This becomes the issue: http://localhost:3000/installations/id?id=1&commit=Create. It can't find the :id. I just don't know how to route this correctly. It seems like this shouldn't be that difficult.

Any help would be great. Thanks.

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

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

发布评论

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

评论(2

溺渁∝ 2024-10-14 06:02:32

我认为您的 form_tag 可能有问题。看来您定义了两次路径。

installation_path([:id])

:url => { :action => "show" }

用于生成路径,但我认为您不应该同时使用两者。只需与

installation_path([:id])

或一起去

:url => { :controller => "installations", :action => "show", :id => id }

I think there might be a problem with your form_tag. It seems you're defining the path twice.

Both

installation_path([:id])

and

:url => { :action => "show" }

are used to generate the path but I don't think you should be using both. Just go with

installation_path([:id])

or

:url => { :controller => "installations", :action => "show", :id => id }
放低过去 2024-10-14 06:02:32

您需要创建并使用一个不基于安装 id 的新“show”路由(并且不会与 Rails 资源路由冲突),并继续将安装 id 作为 params 对象的一部分发送到控制器的 show 操作中。

在routes.rb中,

get 'show_installation', to: 'installations#show'

在您看来,

<% form_tag show_installation_path, :method => :get %>
...

You need to create and use a new "show" route that is not based on the installation id (and doesn't collide with Rails resource routes), and continue to send the installation id into the controller's show action as part of the params object.

In routes.rb,

get 'show_installation', to: 'installations#show'

In your view,

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