The hint option selection disappears when validation fails in Rails

Let me preface by saying that I am noob for Rails and StackOverflow, so please calm down. I am using Rails 2.3.8 with sqlite3 in my dev block.

I created a selection in the form using the following:

<%= select( "communication", "gig_id", { "Add New Gig" => "new"}, {:prompt => "-- Select Gig --"}, :onchange => "toggle(this, 'gigInfo')") %> 

However, when something else on the form fails the test and the โ€œnewโ€ page is re-displayed, my request leaves and the only option is โ€œAdd a new Gigโ€. This is the case with all my forms, and I cannot find an answer about why.

My controller uses basic scaffolding, so I donโ€™t seem to understand. Any help would be greatly appreciated.

+7
select ruby-on-rails prompt
source share
1 answer

Your observation is accurate, and you have acutely noticed that :include_blank remains even when :prompt does not work.

You can achieve the desired results by setting :include_blank to the string that you used for the hint (this should not be logical).

:prompt , it seems, appears only when Rails does not have a value for the given field. When your application re-displays the new view, there is a value for this field because it created an instance of your communication model. (Failed to save this instance, but it looks like this instance has its own set of gig_id fields.)

+12
source share

All Articles