I'm still learning the new world of AJAX and RJS and I got hit by a
problem I could not resolve today.
I have a simple form containing (among other things) a drop_down list
(collection_select with :include_blank => true). This drop_down list
is followed by a div that gets populated when the user selects a value
from the list (I have an observe_field that triggers a method in my
This method has a rjs template file which displays a partial (see code
When the page is initially displayed, the div is empty. As soon as the
user makes a selection, some details about the selection show up in
the view, in the div located under the drop_down list.
All this works fine unless the user decides to reload the page using
the browser's refresh button (or press the F5 key) after having made a
selection in the list.
In this case, the drop_down list continues to show the value selected
before the refresh, however, the div located below the drop_down list
is now empty again.
In other words:
- user loads the page for first time
- user makes a selection in drop_down list => info about selection
shows up in div
- user reloads page => selection is still visible, but info about
selection is not visible anymore
I believe the reason is that the controller's action that manages the
page is called again when the user refreshes the page and the model
associated to the page is reset (i.e. all fields set to nil, since the
controller does @my_model = MyModel.new). But the browser did not
reset the value in the drop_down list so the list and the div are no
longer in sync.
Is there a simple way to solve this problem? or am I doing something
wrong? or am I trying to do something impossible?
Thanks for your help
Rene (aka bubulle)