i am listing items using "select"
on selecting an item-3 from the list iam reloading the page, same for all the items.
When page reloads, select takes to item-1 again.
I want to re开发者_如何学Pythontain item-3 even after page reload.
it's normal if you're reloading the page during, for example, a new action. for edit actions it will load the selected item.
so, if you want to reload the page preserving data/selections, you should create a specific action that takes params[] arguments and load them in the form.
Use select()
as follows:
<%=
select(
"booking",
"airline",
@airlines.collect {|a| [ a.name, a.code ] },
{ :include_blank => true }
)
%>
This will retain the value if the form submits and is returned or the page is refreshed.
The documentation doesn't mention the issue but can be found here:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
精彩评论