Use custom id for check_box_tag in Rails

前端 未结 7 1006
时光说笑
时光说笑 2021-02-04 03:36

How do you set a custom id when using a check_box_tag helper in rails?

I have a loop which creates a bunch of checkboxes based on a collection:

- subject         


        
7条回答
  •  梦毁少年i
    2021-02-04 04:02

    Think I figured it out...

    - subject.syllabus_references.each do |sr|
      = check_box_tag "question[syllabus_reference][#{sr.id}]", sr.id
      = label_tag "question[syllabus_reference][#{sr.id}]", sr.name
    

    This works but if you have a better way let me know!

提交回复
热议问题