views:

41

answers:

1

Trying to create a select menu with items from a collection, so that upon selection of an item, and hitting submit, the user is taken to the "Show" action for that item...What I have is something like this:

<% form_tag("subjects/#{@subject.id}/state/:id", :method=>:get) do %>

<%= select_tag('state', options_from_collection_for_select(State.states, 'id', 'name'))%> <%= submit_tag "go!" %> <% end %>

What'd I like is for what's selected in the menu to fill in the :id parameter...(this is rails 2.3)

A: 

You can send the form to an action that redirect where you want:

<% form_tag("some_controller/redirection", :method=>:get) do %>
  <%= select_tag('id', options_from_collection_for_select(State.states, 'id', 'name'))%>
  <%= hidden_field_tag :subject_id, @subject.id %>
  <%= submit_tag "go!" %>
<% end %>

in SomeController

def redirection
  redirect to "subjects/#{#{params[:subject_id]}}/state/#{params[:id]}"
end
clyfe