开发者

Rails collection_select prompt appears on initial page load, not thereafter. Any fix?

开发者 https://www.devze.com 2023-03-12 04:08 出处:网络
Rails 2.3.11. I have a search form like this... - form_for(@search) do |form| # bla bla bla = form.collection_select(:Location_eq,

Rails 2.3.11.

I have a search form like this...

- form_for(@search) do |form|

  # bla bla bla

  = form.collection_select(:Location_eq, 
      Contract.all_locations, :first, :last, 
      {:prompt => '-- Select --'}, 
      {:class => '开发者_运维技巧ff'})

When the page loads, the first option labeled "-- Select --" (and having value='') appears as expected.

I select an option from that menu and submit the form. The page reloads with the search results. The "-- Select --" option is no longer present in the menu.

This is a problem because the user may want to clear that menu -- take it back to just "-- Select --".

Any way to get the prompt to to survive a form submission?

(I'm using Haml, not Erb, but you get the idea.)


:prompt is behaving as intended. What you're trying to do is :include_blank.

0

精彩评论

暂无评论...
验证码 换一张
取 消