这似乎应该很简单,但它一直在引起我的问题。
我有一个select_tag,从模型中获取数据。我想让人们从下拉列表中选择自己的位置,按提交按钮后跳转到那个位置的页面。
这是我的代码:
<% form_tag installation_path do %>
<%= select_tag :id, options_from_collection_for_select(Installation.find(:all), :id, :name) %>
<div id="button">
<p>
<%= submit_tag "Go", :name => nil %>
</p>
</div>
问题在于它需要一个“:id”,但它不会从下面的下拉菜单中获取“:id”。
我做错了什么,你有其他关于“正确”方法的建议吗?
谢谢
match '/installations',:to => 'installations#show'
。该路由的问题在于,它与索引冲突。因此,您应该有一个特殊的路由:match '/goto_installation' => 'installations#show', :as => 'goto_installation'
。然后在您的表单中:form_tag goto_installation_path,:method => :get do
。在控制器的before过滤器中,您可以redirect_to installation_path(:id => params[:id])
以获得所需的URL。 - Max Chernyak