Rails可迭代创建的可点击标签

时间:2017-03-17 19:20:56

标签: ruby-on-rails forms

我有一个表单,它遍历f.radio_buttonf.label的创建,我正努力让标签可以点击。我对此的理解是标签for应与输入id对齐。我隐藏了无线电图标并设计了范围。

以下是我的简化表格:

<%= form_for(@poll_response, url: responses_poll_path(@poll)) do |f| %> 
  <% @poll_options.each do |option_id, option_value| %>
    <%= f.radio_button :poll_option_id, option_id, :class => 'poll-choice-radio' %>
    <%= f.label :poll_option_id, option_id, :class => 'poll-choice-label' do %>
      <span class="poll-choice-text"><%= option_value %></span>
    <% end %>
  <% end %>
<% end %>

这是HTML输出:

<input class='poll-choice-radio' type='radio' value='1' name='poll_response[poll_option_id] 
id='poll_response_poll_option_id_1'>


<label class='poll-choice-label' for='poll_response_poll_option_id'>
  <span class='poll-choice-text'>Patriots</span>
</label>

我一直在更改标签的第一个和第二个参数,试图让标签for与输入id对齐。我尝试过手动字符串,例如"option_id" + "#{option_id}":poll_option_id_option_id

ruby 2.3.0p0Rails 5.0.1

0 个答案:

没有答案