Home > Mobile >  in rails specific Field Can be show error messages in validation ? different feild can different err
in rails specific Field Can be show error messages in validation ? different feild can different err

Time:07-19

<div >
<% form.label :first_name %>
<%= form.text_field :first_name ,class:"form-control",placeholder:"First_Name" %>
<b><%= @teacher.errors.full_messages.first if @teacher.errors.any? %></b>

plz check my code and solve out full_messages.first is a not a right method.

CodePudding user response:

You can simply use errors.messages and find the error for that field.

<div >
<% form.label :first_name %>
<%= form.text_field :first_name ,class:"form-control",placeholder:"First_Name" %>
<b><%= @teacher.errors.messages[:first_name].join(", ") %></b>

There are many articles and SO post for the same. You can refer to them as well

  • Related