Validation Error Messages not Displaying – Ruby on Rails

Just another quick problem I ran into, the validation was indicating that an error had occurred however it did not show what the error was:

1 error prohibited this message from being saved:

— Usually an error would appear here —

Turns out the problem was pretty straight forward – it’s always the little things! I’d simply missed the each when displaying the error messages:

<%= form_for @location do |f| %>
  <% if @location.errors.any? %>
    

<%= pluralize(@location.errors.count, "error") %> prohibited this message from being saved:

    <% @location.errors.full_messages do |msg| %> <% #Should have been: @location.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>

Simply adding the correct code fixed the problem straight away.

1 error prohibited this message from being saved:

Country can’t be blank

Good Luck!

Leave a Reply