如何在复选框 simple_form 上添加标签并将标签样式内联到复选框?

How to add a label on the checkbox simple_form and style the label inline to the checkbox?

我有一个没有标签的复选框。如何在 simple_form 中添加标签标签,其中在 HTML 标签标签中插入了复选框。

我现在后面有复选框和纯文本。

    <%= f.check_box :is_positive, as: :boolean, checked_value: true, unchecked_value: false %> Is positive?

我尝试了下面的代码,但它使标签高于实际的复选框。

    <%= f.input :is_positive, as: :boolean, checked_value: true, unchecked_value: false, inline_label: 'Is positive?' %>

有没有办法标记复选框并将其标签内联到复选框?

请尝试下面的代码,您可以使用 css 将标签的样式更改为您喜欢的任何样式:

<%= f.label :is_positive do %>
  <%= f.check_box :is_positive, as: :boolean, checked_value: true, unchecked_value: false %> <span class="labelText">Is positive?</span>
<% end %>