LoginSignup
2
3

More than 5 years have passed since last update.

Rails: バリデーションエラーをViewに表示する

Last updated at Posted at 2015-11-23

Remember our .errors.full_messages from using ActiveRecord before? We'll just go through each error message and display it as part of a bulleted list:

<%= form_for @movie do |f| %>
  <% if @movie.errors.any? %>
    <div>
      <%= pluralize(@movie.errors.count, "error") %> prevented this movie from being submitted:
      <ul>
        <% @movie.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  [...]
<% end %>
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3