I have some checkboxes on a HAML doc, which should change the results displayed when I click the 'refresh' button. This works fine, but when the page reloads the boxes that were checked are all unchecked again.
How do I reconfigure the HAML to persist the checkboxes checked state across page views?
= form_tag movies_path, :method => :get do
Include:
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]", '1', true
= submit_tag 'Refresh'
I have also specified that the checkboxes should be checked by default, but they aren't checked when I load the page...
This will accomplish what you want:
= form_tag movies_path, :method => :get do
Include:
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]", rating, if params[:ratings]; params[:ratings].include?(rating) end
= submit_tag 'Refresh'
The params[:ratings] instance persists after the call, so you can just use it to mark the boxes that where clicked by the user before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With