vendredi 28 décembre 2018

How to use ternary operator for checkbox in haml?

I am confused about how to use the haml syntax for ternary operator to check if a checkbox is checked or not. I have a color_id column which stores values based on which checkbox is checked. Below is my code:

  .dress_color
    .form-group
    .checkbox.checkbox-primary.color_id
     = f.check_box :color_id, {}
     %label= t('.dark color')

    - if f.object.long_dress_selected?
          ...............
    - else
      = f.check_box, checked: true ? ('color_id: black') : ('color_id: white')

I want to check whether the 'dark_color' check box is checked or not, in the else part of the if-else condition. That is, if the checkbox is checked, color_id should be set to 'black' else it should be set to 'white'. But the above code is showing error as:

SyntaxError -html.haml:19: syntax error, unexpected tLABEL, expecting '='
_false(( f.check_box, checked: true ? ('color_id
                              ^:

How to check the whether the checkbox is checked or not by using ternary operator?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire