简体   繁体   中英

:selected values are resetting in page submit

Selected values from dropdown are resetting in page submit.here is the code am using

<%=select_tag 'num_id', options_for_select(@numbers.collect{ |t| [t.firstno]}),:prompt => "Select"%>

How can we set the selected value inside a select_tag in ruby on rails.

您可以将另一个参数传递给options_for_select来设置选定的选项

<%= select_tag 'num_id', options_for_select(@numbers.map(&:firstno), params[:num_id]), prompt: 'Select' %>

select_tag selected value -

options_for_select(@options, @selected_val)

Example:

 options_for_select(1..8, 5)  # creates options from range 1..8, with 5 as selected by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM