When I create multiple buttons for the same form in Rails, I can use the value of param[:commit] to figure out which button was pushed.
How do I create multiple submit buttons for the same form in Rails?
However, I have a search results page where a user can further refine the search, updating the results by selecting or deselecting facets, changing date filters, etc. I'd like to be able to trigger a form.submit() using javascript when a facet checkbox is checked/unchecked, for example. How do I pass a parameter (such as the param[:commit] mechanism) to my controller so that I know which user action triggered the refresh. I don't want to make everything a button.
$('.facet').on('change', function(e) {
// Do some stuff
var $form = $(this).closest('form');
$form.submit(); // I want to pass in a "facet-selected" here so I know what triggered the submit
});
With a controller method that looks like this
def refresh_search
if params[:commit] == 'facet-selected'
# Do something
elsif params[:commit] == 'date-range-changed'
# Do something else
end
end
Thanks so much in advance.
Christy