我有一个表单,它遍历f.radio_button
和f.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.0p0
和Rails 5.0.1