开发者

Select_tag submitted needs to redirect to show page with :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.


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 }


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 %>
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜