0

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)
  )
Brian Postow
  • 11,709
  • 17
  • 81
  • 125

1 Answers1

0

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
Michael C
  • 11
  • 2
  • I agree t hat this is likley to be the correct solution, but I don't seem to have \@client (the equivalent of \@user here)... I have a HAML, and a coffee, but no actual rb files, so no controller to tell about \@user? Is that how this is supposed to work? – Brian Postow Mar 18 '19 at 22:48
  • I'm not sure if this will work, because there isn't really a "submit" button... It's just, there's a checkbox, andif you check it, and kill the popup, it gets registered... – Brian Postow Mar 19 '19 at 23:36
  • You need to define a controller for this view. Without a controller you aren't going to have any way to manage the views. If the form_for doesn't work in this context, then look at making an Ajax call from the pop-up to the update action in the controller for that client. In either case, you will need a controller to handle these requests. If you want to try the form_for still, you can have the submit button triggered on the click of the checkbox, and have a hidden field that contains the relevant details to update that column in the table. – Michael C Mar 20 '19 at 15:57