selected value of f..select lost after page refresh in ruby on rails -
i have dropdown in ruby on rails i.e below:
<table> <tr> <td align="center"> <%= f.select(:interest,options_from_collection_for_select(@students, "id", "student_mentor_subjects"), {},:id => "ddl_students", :style => "width:160px;") %> </td> </tr> </table> and students table populating f.select , below schema of students table:
id | student_mentor_subjects 1 | ijk 2 | mno 3 | pqr and when select value above f.select , click on search button page refresh , selected value lost, how retain selected value of f.select after page refresh. kindly me, thanks.
from api:
options_from_collection_for_select(collection, value_method, text_method, selected = nil)
the fourth argument options_from_collection_for_select default value. in case need set params, fall specific default if there's nothing in params (which case when load page first time).
i don't know value read params you've not posted rest of form, if in log should see value want read. so, might
<%= f.select(:interest,options_from_collection_for_select(@students, "id", "student_mentor_subjects", params[:search][:interest] || @students.first.id), {},:id => "ddl_students", :style => "width:160px;") %>
Comments
Post a Comment