Styling form error message - bootstrap/rails

前端 未结 8 744
陌清茗
陌清茗 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:16

    I have implemented Rabbott's view helper in Rails 5 and Bootstrap 4:

    def errors_for(object)
        if object.errors.any?
          content_tag(:div, class: 'card text-white bg-danger mb-3') do
            concat(content_tag(:div, class: 'card-header') do
              concat(content_tag(:h4) do
                concat "#{pluralize(object.errors.count, 'error')} prohibited this #{object.class.name.downcase} from being saved:"
              end)
            end)
            concat(content_tag(:div, class: 'card-body') do
              concat(content_tag(:ul) do
                object.errors.full_messages.each do |msg|
                  concat content_tag(:li, msg)
                end
              end)
            end)
          end
        end
      end
    

    And it looks like this:

提交回复
热议问题