How to simply check a checkbox in rails

How do you simply confirm that the checkbox is set on the rails? The checkbox is intended for agreement with the end user. And he is in the modal window.

Suppose I have a checkbox:

<%= check_box_tag '' %>


Where and how should I check this?

I saw most of the check box check messages in rails here, but none of them fit my needs.

+5
source share
1 answer

Adding

validates :terms_of_service, :acceptance => true

Your model should do this. See here for more details .

However, if accepting the conditions is not part of the form for your model, you should use client-side validations, i.e. JavaScript, like this (in jQuery):

function validateCheckbox()
{
    if( $('#checkbox').attr('checked')){
      alert("you have to accept the terms first");
    }
}

script :

<%= javascript_include_tag "my_javascipt_file" %>

:

<%= submit_tag "Submit", :onclick: "validateCheckbox();" %>

: : check_box_tag :checkbox. HTML : <input id="checkbox" . .

+14

All Articles