Ruby-on-rails – Error message in Ruby on Rails

I implemented the validates_presence_of field for the comments in the guide. How to display validation errors on the post page. I know the rendering, but with the rendering I need to send all the variables I use on the post page . Am I right?
I don’t believe that plugins are necessary. The scaffolding generator in Rails 3.x does this:

<%= form_for(@model) do |f| %>
<% if @model.errors.any? %>
< div id="error_explanation">

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




    <% @model.errors.full_messages.each do |msg| %>
  • <%= msg %>

  • <% end %>


<% end %>
<%# Rest of form... %>

I implemented the validates_presence_of field for the comments in the guide. How to display validation errors on the post page. I know the rendering, but there is rendering. I need to send all the variables I use on the post page. Am I right?

I don’t believe that plugins are necessary. The scaffolding generator in Rails 3.x does this:

<%= form_for(@model) do |f| %>
<% if @model.errors.any? %>

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


    <% @model .errors.full_messages.each do |msg| %>
  • <%= msg %>

  • <% end %>


<% end %>
<%# Rest of form... %>

Leave a Comment

Your email address will not be published.