How can I show form errors under the fields instead of the top of the form?
How I can make something like this:
<%= text_input u, :username %>
to render something like this, if there is an error in this field ->
<div class="field-with-error">
<input type="text">
<span class="error">This username is already taken</span>
</div>
Now you can use:
<%= error_tag f, :firstname %>
The errors are all in the errors field of the form struct, so you can typically access them as f.errors
. Here is an example:
<%= if message = f.errors[:username] do %>
<span><%= translate_error(message) %></span>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With