gpt4 book ai didi

ruby-on-rails - simple_form collection_Radio_buttons 生成额外的标签

转载 作者:太空宇宙 更新时间:2023-11-03 17:15:06 25 4
gpt4 key购买 nike

我有以下 ruby :

<%= simple_form_for @answer, url: presentation_survey_path(@presentation) do |f| %>
<%= f.collection_radio_buttons :option_id, @question.options_array, :first, :last, {label: false} do |b| %>
<div class="col-sm-4">
<%= b.label(class: 'btn btn-large', style: 'margin-right: 20px; margin-left: 20px;') {b.radio_button(id: b.object.last, class: 'answer-input', style: 'display: none;') + b.text } %>
</div>
<% end %>

它正确地生成了 html,除了它生成了两个标签:

<span>
<label for="answer_option_id_15">
<div class="col-sm-4">
<label class="btn btn-large" for="answer_option_id_15" style="margin-right: 20px; margin-left: 20px;">
<input class="answer-input" id="Way too many" name="answer[option_id]" style="display: none;" type="radio" value="15" />
Way too many
</label>
</div>
</label>
</span>

出于某种原因,它正在生成第一个标签。我只想保留第二个。标签:false 不起作用。如何去掉第一个标签?

最佳答案

根据docs :

For check boxes and radio buttons you can remove the label changing boolean_style from default value :nested to :inline.

此外,simple_form 有一些用于 collection_radio_buttons 的选项,这些选项记录在代码中:

# Collection radio accepts some extra options:
#
# * checked => the value that should be checked initially.
#
# * disabled => the value or values that should be disabled. Accepts a single
# item or an array of items.
#
# * collection_wrapper_tag => the tag to wrap the entire collection.
#
# * collection_wrapper_class => the CSS class to use for collection_wrapper_tag
#
# * item_wrapper_tag => the tag to wrap each item in the collection.
#
# * item_wrapper_class => the CSS class to use for item_wrapper_tag
#
# * a block => to generate the label + radio or any other component.

在我的例子中,将 item_wrapper_tag 设置为 false 并将 boolean_style 设置为 :inline 就可以了,例如:

<%= f.collection_radio_buttons :option_id, @question.options_array, :first, :last, boolean_style: :inline, item_wrapper_tag: false do |b| %>

关于ruby-on-rails - simple_form collection_Radio_buttons 生成额外的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29975087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com