8

This seems like it should be so simple but it has been causing me issues.

I have a select_tag that pulls from a model. All I want to is have a person choose their location from the drop down, press submit and take it to that places page.

Here is what I have

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

The problem is it of course wants an :id but it won't pull the :id from the drop down menu below.

What am I doing wrong, any other suggestions on the "right" way to do this.

Thanks

1 Answer 1

8

Looks like you actually want to GET, not to POST the params.

form_tag installation_path, :method => :get do
Sign up to request clarification or add additional context in comments.

3 Comments

First off thanks! Using the wrong method was def one problem. However in order to have the routes correct it needs to be installation_path(id). However the id pulled is the id of the array from the collection_select. Any ideas? It really doesn't seem like this simple task should be so difficult.
Here's the thing, you want to submit the form, and go to /installations/:id. Instead you will end up in /installations?id=:id. So you could give Rails a route match '/installations', :to => 'installations#show'. The problem with that route is — it conflicts with index. So instead you should have a special route: match '/goto_installation' => 'installations#show', :as => 'goto_installation'. Then in your form: form_tag goto_installation_path, :method => :get do. Then in your controller's before filter you can redirect_to installation_path(:id => params[:id]) to get the desired url.
Hi I am just getting back to this, it turns out I can not use "match" because I am not running rails3 yet. Any ideas on how else to do this. I just can't understand why this is so complicated. It seems like this is done all the time yet I can't seem to find any guidance. Thanks in advance. I appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.