Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Evanto/1b8abdb2b12dfe2838c1b0f194080eb0 to your computer and use it in GitHub Desktop.
Save Evanto/1b8abdb2b12dfe2838c1b0f194080eb0 to your computer and use it in GitHub Desktop.
I had a code in the form:
<%= simple_form_for @card do |f| %>
<% if @card.errors.any? %>
<% @card.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
<% end %>
<p><%= f.label "* Вопрос:" %></p>
<p><%= f.input :original_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><%= f.label "* Ответ:" %></p>
<p><%= f.input :translated_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><% f.date_field :review_date %><br>
<p><%= f.button :submit, "Создать" %></p>
<% end %>
And this gave me messages which included names of the db table's columns. So how do I remove them from the view?
Correct code to solve this problem:
<%= simple_form_for @card do |f| %>
<% if @card.errors.any? %>
<% @card.errors.messages.values.each do |msg| %>
<%msg.each do |m| %>
<li><%= m %></li>
<%end %>
<%end %>
<% end %>
<p><%= f.label "* Вопрос:" %></p>
<p><%= f.input :original_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><%= f.label "* Ответ:" %></p>
<p><%= f.input :translated_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><% f.date_field :review_date %><br>
<p><%= f.button :submit, "Создать" %></p>
<% end %>
answer found here:
http://stackoverflow.com/questions/5375407/removing-field-name-from-validation-error-
Use debug to see this object in the view:
<%= simple_form_for @card do |f| %>
<% if @card.errors.any? %>
<% @card.errors.messages.values.each do |msg| %>
<%msg.each do |m| %>
<li><%= m %></li>
<%end %>
<%end %>
<%= debug(@card.errors.messages) %>
<% end %>
<p><%= f.label "* Вопрос:" %></p>
<p><%= f.input :original_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><%= f.label "* Ответ:" %></p>
<p><%= f.input :translated_text, label: false, placeholder: "не больше 200 символов" %></p>
<p><% f.date_field :review_date %><br>
<p><%= f.button :submit, "Создать" %></p>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment