如何正确配置simple_form标签

How to configure simple_form label correctly

我有一个现成的 html 布局。它看起来像这样(!SLIM USING!):

label.modal__form-label Имя
input.modal__form-control type="text" required="" minlength="3"

它生成此代码:

<label class="modal__form-label">Имя</label>
<input class="modal__form-control" minlength="3" required="" type="text">

这就是我需要的。

我粘贴了我的 ruby​​code 而不是这个。 Ruby代码:

= f.input :name, input_html: { minlength: "3", type: "text" }, required: true

并得到这个 html:

<label class="string required" for="feedback_name"><abbr title="required">*</abbr> Name</label>
<input class="string required modal__form-control" minlength="3" type="text" required="required" aria-required="true" name="feedback[name]" id="feedback_name">

如您所见,我需要给一个 class 标签,并将 :name 重命名为简单形式的“Имя”。我怎样才能做到这一点?

labellabel_html 应该是您正在寻找的其他选项。所以把它们放在一起:

= f.input :name,
          input_html: { minlength: "3", type: "text" },
          label_html: { class: "modal__form-label" },
          label: "Имя",
          required: true