Reputation: 12217
I'm pretty sure I'm being an idiot here, but I've been out of Ruby long enough that my searching isn't coming up with the right answer.
I have a popup with a checkbox. I want, if the user checks the checkbox, to set a flag in the Users table so that the checkbox doesn't come up again.
I already have the code for if the thing is set, the popup doesn't come up. I'm having trouble getting the checkbox state-change back to the DB...
The checkbox code look like this:
%button.btn.btn-primary.slide_show_next{:type => "button", :data => {:toggle => "modal", :target => "#help_slide_show_2", :dismiss => "modal"}}
Next
.show-slideshow
%label
%input.show-slideshow-checkbox{:type => "checkbox", :checked => "checked"}
Show me this when I view a report.
The relevant coffeeScript is:
$ ->
if typeof(gon) != 'undefined' && gon.show_help_slide_show == true && document.cookie.indexOf("show-slide-show=false") == -1
$("#help_slide_show").modal()
if document.cookie.indexOf("show-slide-show=false") != -1
$(".show-slideshow-checkbox").attr("checked", false)
$(".show-slideshow-checkbox").change( (event) ->
val = $(event.target).prop("checked")
document.cookie = "show-slide-show=#{val}; Path=/;"
$(".show-slideshow-checkbox").attr("checked", val)
)
Upvotes: 0
Views: 44
Reputation: 11
Look into form_for. That will help you update the model from the view. The code for a haml form_for is below, and the erb equivalent can be found in the form_for documentation. I find that haml documentation isn't as robust as I'd like for certain syntax questions.
= form_for @user, remote: true do |f|
= f.label 'checkbox'
= f.check_box :table_column, autofocus: true
= f.submit
Upvotes: 0