Thanks for reading this. I have an index view in my rails app. it has an area where i display a list of records. i use an instance variable called @list to hold the array of records. i have a couple of buttons on the form that remotely renders the list in either a grid or a list format. everything works great - i have a grid_partial and a list_partial, and i use JS to render whichever view the user clicks on.
i recently added a feature that allows the user to select the ordering criteria for the list (order by price: ascending, delivery date: descending, etc.). when they click on an ordering scheme, i ajax a method in the controller that updates the value of @list. the update method then calls a js.erb file that renders the partial. it does this correctly as the @list records are now in the order the user requested. My issue occurs when i click one of the buttons to switch between list and grid view. when i do this, the list and grid partials use the original, un-updated version of @list, NOT the value i most recently received from the last AJAX communication to the server. Both of my partials reference the @list instance variable to get the array.
It was my intent to be able to update/overwrite the value of @list, so that subsequent rendering of partials that reference @list would use the new, updated value. Is this possible?
I have tried to replace the @list variable with a local variable that is passed into each partial, but that doesn't fix the problem. Thanks in advance for your consideration.