Question

I have a Rails 4 application using sunspot for search functionality. I have successfully set up a number of facets using the attributes of a particular model. On clicking one of the options in a facet I get the filtered list of records returned as well as an updated count of the records now available for each facet option. Now when clicking on one of those updated facet options I would expect to get the concatenation of both the primary facet option choice and the current choice, i.e. creating a url along the lines of /instances?mykey1='A'&mykey2='B'

But the url is only taking the most recently clicked option and thus disregarding the initial filter.

How do I persist the initial filter into the second filter query?

(I note that this question is very similar to

Rails & Sunspot facets and filtering

however that post didn't appear to resolve things.)

Regarding my code it pretty much follows the standard code format laid out in railscasts (Rails & Sunspot facets and filtering) with the addition of a second facet. I can replicate it here if necessary

Has anybody done this (surely this is a common feature?) and can help me out?

Regards

Was it helpful?

Solution

Assuming your facets are laid out in the same manner as the example you provided, you should be able to merge in the second facet option into the current request params. So this:

<%= link_to row.value, :month => row.value %>

...becomes this:

<%= link_to(row.value, params.merge({ :month => row.value })) %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top