如何访问options_for_select中的ID?

时间:2018-10-08 13:37:57

标签: ruby-on-rails ruby

我正在尝试在Ruby Rails中获取选择的ID。选择本身包含名称和带有字符串的数据值,例如:

<div class="item" data-value="3,1,">test1</div>

但是我也想包括每个元素的第三部分,例如data-id。我用于选择的数组(@user_templates)

[["test1", 80, "1,2,"], ["test2", 81, "1,2,612,"], ["test3", 82, "1,2,612,4,"], ["test4", 83, "1,2,"], ["test5", 84, "3,1,"]]

因此它应该类似于:

<div class="item" data-value="2,1," data-id="80">test1</div>

我的.haml代码:

          - if @program.id.nil? || @program.completed?
            .field
              = label_tag :program_template, I18n.t('texts.6F').capitalize
              - path = params[:program_template] ? new_account_patient_program_path(@patient) : reuse_account_patient_program_path(@patient, @program)
              .select= select_tag :program_template, options_for_select(@user_templates,
                                  selected: params[:program_template]) + options_for_select(template_options,
                                  selected: params[:program_template]),
                                  onchange: "if(this.value != '#{params[:program_template]}' && this.value != ''){window.location.href = '#{path}'+'?program_template='+this.value; console.log(this.value); console.log('#{params[:program_template]}')}"

0 个答案:

没有答案