提交的 select_tag 需要重定向到显示带有 :id 的页面?
你好 我之前问过类似的问题,但一直没有解决。所以我再次尝试。
这看起来应该是这么简单。顺便说一句,我还没有使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的 form_tag 可能有问题。看来您定义了两次路径。
都
和
用于生成路径,但我认为您不应该同时使用两者。只需与
或一起去
I think there might be a problem with your form_tag. It seems you're defining the path twice.
Both
and
are used to generate the path but I don't think you should be using both. Just go with
or
您需要创建并使用一个不基于安装 id 的新“show”路由(并且不会与 Rails 资源路由冲突),并继续将安装 id 作为 params 对象的一部分发送到控制器的 show 操作中。
在routes.rb中,
在您看来,
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,
In your view,