mardi 5 mai 2015

Avoiding eval when building radio buttons in rails

Here, I am building database driven radio buttons. I wanted to know if there is a way I can avoid eval and see checked is true or not !Thanks,

Index Controller

 columns = Model.column_names  

View in haml

- columns.each do |cols|
      - check = "c[0].#{cols}==1? true : false" // checking value here
      - negcheck = "c[0].#{cols}==0? true : false"// checking value here    
      - pluckid = "c[0].id"
      - id = eval(pluckid)
      %tbody
         %td #{cols}
         %td
          = label_tag 'On'
          = radio_button_tag("ABC",1,checked = eval(check), options = {})
          = label_tag 'Off'
          = radio_button_tag("xyz",0,checked = eval(negcheck), options = {})

Aucun commentaire:

Enregistrer un commentaire