Last active
May 7, 2017 21:51
-
-
Save Evanto/1b8abdb2b12dfe2838c1b0f194080eb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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