views:

99

answers:

1

Hey guys,

My question is simple. Can I add either of the blow

:prompt => "Any"
:include_blank => true

to a form in form_tag.

Here is an example. I would like to add :prompt to the select_tag :condition and select_tag :category fields and am having trouble.

 <ul id="homepage_searchbar">
<% form_tag junklists_path, :method => :get do %>
  <li>
    <%= image_tag('search_icon.png', :id => 'main_search_icon' ) %>
  </li>
  <li>
    <%= text_field_tag :search, "I'm looking for junk called...", :id => "main_field" %>
  </li>
  <li>
       <%= select_tag :condition, options_for_select(Condition.all.collect{|condition| [condition.name, condition.id]}) %>
  </li>
  <li>
       <%= select_tag :category, options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}"})%>
  </li>
  <li>
    <%= submit_tag "Go!", :name => 'main_submit', :id => "main_submit" %>
  </li>
<% end %>
</div>

If I can't do it the way I want, how can I add a field at the top of the select boxes that has the text "Any" but has no value when the form is submitted?

Thanks in advance!

+1  A: 

Look at the documentation for options_for_select. You're ultimately just passing in arrays of arrays to it, so you can prepend whatever you want to appear at the top of the list.

options_for_select([["Any", "-"]] + your_method_for_generating_your_options_list)
jdl
thanks! i had looked in the form_tag docs and form_for docs as I had written this using :prompt for form_for but did not think to do it this way through options_for_select >.<. I appreciate the help!
bob