Styling form error message - bootstrap/rails

前端 未结 8 608
陌清茗
陌清茗 2021-02-01 18:38

The error messages for my rails form look terrible with bootstrap. Does anyone know a solution for better (nice looking) error messages? I use Rails and Bootstrap.

My fo

8条回答
  •  北海茫月
    2021-02-01 19:19

    Take a look at how Michael Hartl does it in railstutorial. screenshot

    And thats the used css:

    #error_explanation {
      color: #f00;
      ul {
        list-style: none;
        margin: 0 0 18px 0;
      }
    }
    
    .field_with_errors {
      @extend .control-group;
      @extend .error;
     }
    

    He describes everything here.

    If you also want the little star at the beginning of every line you have to include it in your form:

         

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

      <% @user.errors.full_messages.each do |msg| %>
    • * <%= msg %>
    • <--- insert here <% end %>
    ...

提交回复
热议问题