Answer the question
In order to leave comments, you need to log in
How to display validation error message in Rails?
If validation is present in the User model, such as:
validates :name, :login, presence: true, then if this validation is not observed, errors should be displayed.
How can I display a list of errors in the view and where are these messages located in order to change them ???
Answer the question
In order to leave comments, you need to log in
Example of error output:
<% if @article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
Make yourself a partial, for example _error_messages.html.erb
, and then before each form, where errors will be displayed, render this partial.
for example you have a registration form
<%= form_for(@user, url: register_attempt_path, html: { class: 'form-wrapper form-medium' }) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.text_field :username, class: 'form-control margin_form_control', placeholder: 'username' %>
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question