在标签标题后显示错误信息

Display the error message after the label title

我的表格使用了这样的简单表格:

<%= f.input :last_name %>

当表单出现验证错误时,验证错误消息会显示在输入文本框之后,如下所示:

<div class="input string required test_last_name field_with_errors"><label class="string required" for="test_last_name"><abbr title="required">*</abbr> Last name</label>
<input class="string required" id="test_last_name" name="test[last_name]" type="text" value="">
<span class="error">can't be blank</span>
</div>

我想生成如下所示的 html 以在标签后显示消息:

<div class="input string required test_last_name field_with_errors"><label class="string required" for="test_last_name"><abbr title="required">*</abbr> Last name</label> <span class="error">can't be blank</span>
<input class="string required" id="test_last_name" name="test[last_name]" type="text" value="">
</div>

任何帮助将不胜感激。

谢谢 萨布

希望不大,但请尝试

<%= f.input :last_name as: :required %>

我把 2 和 2 放在一起,这是一个 ruby 事后的项目。

<div class="input string required test_last_name field_with_errors"> <label class="string required" for="test_last_name"><abbr title="required">*</abbr> Last name</label><span class="error"> can't be blank</span>
<input class="string required" id="test_last_name" name="test[last_name]" type="text" value="">
   
</div>

我找到了答案并将其张贴在这里,希望对某些人有所帮助。

在简单的配置文件中,只需将错误标记放在输入之前,如下所示:

b.use :error, wrap_with: { tag: :span, class: :error }

b.use :label_input

并在错误 class 上添加此 css:

float:right

谢谢

萨布