Rails: Reload Page with Params Entry on Checkbox Click

2018-01-02 · 1 min read

The following snippet will reload the page once the checkbox is clicked with a new parameter being added to the URL.

= form_tag the_current_path, method: :get do |f|
  = check_box_tag :custom_filter, true, params[:custom_filter], onchange: 'this.form.submit();'
  = label_tag :custom_filter, "Custom Filter"

Subscribe to My Newsletter

The latest programming-related news, articles and resources - sent to your inbox monthly. Unsubscribe anytime.