rails add :prompt to form_tag fields?

Posted by bob on Stack Overflow See other posts from Stack Overflow or by bob
Published on 2010-04-19T02:27:08Z Indexed on 2010/04/19 2:33 UTC
Read the original article Hit count: 298

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!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby