select drop down list

I'm having some trouble with this select tag.

I have a simple search form that passes parameters with GET. I have the
search by name working fine but want to add a drop down list to search
by classification as well.

here is what i have:

<% form_tag items_path, :method => 'get' do %>
  <table>
    <tr><%= link_to 'New Item', new_item_path %><td></tr>
  <tr><td><%= text_field_tag :search, params[:search] %></td>
  <td><%= select("class","id", @classifications.map {|u| [u.name,u.id]})
%>
    <td><%= submit_tag "Search", :name => nil %></td></tr>
  </table>
<% end %>

it works but the url looks like:
http://domain.com/items?search=&class[id]=1

because it is sending class[id]=1

i would like it to send just class=1 (or whatever the classification id
is)

also, is there a good way to add a :prompt (although i don't think this
is possible with just a select tag) so if a user does not select a
classification then it will not pass a GET parameter.

thanks!

Guess you could do it like this:

<%= select("class","id", @classifications.map {|u| [u.name,u.id]},
{:prompt => 'Select an option'}) %>

answer to your first question is:

if !(params[:class] && params[:class][:id].blank?)
      @items = Item.search(params[:search], params[:class][:id],
params[:page])
    else
      @items = Item.search(params[:search], "", params[:page])
    end

for your question, I assume you want something like
http://domain.com/items?search=&class=1

to achieve that you could use the select_tag like so:
select_tag(:class, options_for_select(@classifications.map {|u|
[u.name,u.id]}))

hope that helps

http://www.sphred.com
http://www.nasir.wordpress.com

nas wrote:

answer to your first question is:

if !(params[:class] && params[:class][:id].blank?)
      @items = Item.search(params[:search], params[:class][:id],
params[:page])
    else
      @items = Item.search(params[:search], "", params[:page])
    end

for your question, I assume you want something like
http://domain.com/items?search=&class=1

to achieve that you could use the select_tag like so:
select_tag(:class, options_for_select(@classifications.map {|u|
[u.name,u.id]}))

hope that helps

http://www.sphred.com
http://www.nasir.wordpress.com

On Jul 21, 10:34 pm, Scott Kulik <rails-mailing-l...@andreas-s.net>

ah ok thanks i got it working like this since i wanted to add a prompt:

<%= select_tag(:classification_id, '<option
value="">->Base/Class</option>' +
options_from_collection_for_select(@classifications, :id, :name)) %>

the only issue i'm running into now is how can i get the select box to
select the same value after the form is submitted?

i know how to do this with collection_select but not sure it is possible
with select_tag.

can you do something similar to the following (this doesn't work)?

<%= select_tag(params[:classification_id], :classification_id, '<option
value="">->Base/Class</option>' +
options_from_collection_for_select(@classifications, :id, :name)) %>

thanks for the help so far!