I'm trying to find a way to send params to a controller action when a checkbox is clicked in a Rails 7 web app. However, I don't have any form that gets submitted. The checkbox will be used to filter items in the index view.
I don't want to use jQuery/AJAX if possible, I have Stimulus/Hotwire in the web app so if there is a way to incorporate Stimulus that's also an option.
I currently have a link that handles sending param's to the controller, but I would like to replace it with a checkbox.
<%= link_to "red", cars_path(request.params.merge(color: 'red')) %>
I tried using onclick but couldn't get it working.
<%# check_box_tag(:color, "red", checked=false, { disabled: false, onclick: "#{cars_path(request.params.merge(color: "red"))}" }) %>