I have a controller (with RoR, but let’s assume I have some server listening for a request) that deals with the search of hotels. The default search is by city, so given a city, the controller will look for all the hotels in that city.
Once that view is rendered, I have a form that lets you filter the results. My question is:
How am I supposed to save the current state of the user preferences (filters and city) in order to send them to the controller action again?
So, let’s say that the user clicks on sort by price, and via AJAX I want to fetch the hotels for a given city (chosen before) ordered by price. How do I know which city he has chosen before? Do I need to store it in a hidden field or what’s the appropriate way of doing so?
Same question rises if after filtering the order by price, the user selects the luxury hotels option. I need to fetch hotels by a given city, ordered by price and with category of luxury. Where am I supposed to store the prior states of the search?
Thanks
You could store the prior states simply in a JavaScript variable or a hidden form field. Either is fine, and the right choice will depend more on your code design than on any kind of functionality/performance issue. And if you can’t figure out which way is better for your particular case, don’t worry about it because it probably just doesn’t matter.