Simple_form and custom validation message
Introduction:
Using simple_form
in the application, the added attribute and error checks appear correctly next to each field in the form. Also, I have 2 custom validations that add custom error messages not related to model attributes.
Problem:
In basic rails forms, errors are displayed above the form, and also those that cause custom validation appear. But how can I show custom validation messages using simple_form
?
+3
source to share
2 answers
I came up with this so far:
<% if @object.errors.messages[:base].present? %>
<ul class="error_messages_container">
<% @object.errors.messages[:base].each do |e| %>
<li><%= e %></li>
<% end %>
</ul>
<% end %>
which I placed above the form, so I will have my custom validation messages above the form. Also, waiting for other ideas.
+1
source to share