Displaying simple_form error messages in top

前端 未结 1 2104
悲哀的现实
悲哀的现实 2021-02-07 06:55

I have the following two _forms:

user form

<%= simple_form_for(@user, :url => @target) do |f| %>
  <% if @user.errors.any? %         


        
1条回答
  •  不要未来只要你来
    2021-02-07 07:09

    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? %>
      
    The form contains <%= pluralize(object.errors.count, "error") %>.
      <% object.errors.full_messages.each do |msg| %>
    • * <%= msg %>
    • <% end %>
    <% 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 %>
    

    0 讨论(0)
提交回复
热议问题