keep values after submit
I know how I can keep my form where I ha开发者_开发问答ve a select list is not deleted after a submit?
This is the line I use to fill the select list:
<% = select: search,: style, [[All, ""]] + Proyect.all (: group => "style",: order => "style"). collect {| a | [a. style a.estilo]}%>
please help me
Thanks in advance
yeah. was very simple.
Solved with the folowing parameters added to the current line:
{:selected=>params[:search][:style]}
thus leaving
<% = select: search,: style, [[All, ""]] + Proyect.all (: group => "style",: order => "style"). collect {| a | [a. style a.estilo]},{:selected=>params[:search][:style]}%>
thanks anyway
-------------------ANNEX---------
That's right, but my solution, half good solution, because I have the problem that if the parameter still not been created?
How to do something like this:
{: selected => params [: search] [: style] if params [: search] [: style]! = nil}%>
being as follows:
<% = select: search,: style, [[All, ""]] + Proyect.all (: group => "style",: order => "style"). collect {| a | [a. ]},{: a.estilo style selected => params [: search] [: style] if params [: search] [: style]! = nil}%>
any ideas?
You need to set what option is selected. This case the 2nd one is selected:
<%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>
See here for explanation
精彩评论