Displaying simple_form error messages in top <div>

别等时光非礼了梦想. 提交于 2019-12-03 05:13:35

Just add error: false to your inputs this will not clear the css but will clear the inline errors

f.input error: false or :error => false

Edit:

From http://ruby.railstutorial.org/book/ruby-on-rails-tutorial

/app/views/shared/_error_messages.html.erb

 <% if object.errors.any? %>
  <div id="error_explanation">
   <div class="alert alert-error">
     The form contains <%= pluralize(object.errors.count, "error") %>.
   </div>
  <ul>
   <% object.errors.full_messages.each do |msg| %>
    <li>* <%= msg %></li>
   <% end %>
 </ul>
</div>
<% end %>

in VIEW

<%= form_for(@user) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :email %>
  <%= f.text_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.label :password_confirmation, "Confirmation" %>
  <%= f.password_field :password_confirmation %>

  <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!