0

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.

paulozag
  • 1
  • 1

1 Answers1

0

Based on the limited information available I am guessing the controller that renders the list/grid partial on clicking the button is not aware of the altered ordering scheme.

you may consider either passing that information from the client as a query parameter, or save it in session.

lorefnon
  • 12,875
  • 6
  • 61
  • 93
  • the switch between list and grid isn't done thru a controller - i have listeners on two buttons that re-render the screen in either list or grid mode. all of this is done locally, with no update to the @list variable and no communication to the controller. – paulozag Nov 22 '15 at 19:37