Arturo Gabriel
Arturo Gabriel

Reputation: 119

How to manage errors with simple_form in rails 6

I have a form where I have added some validation, I would like the errors to be listed, I have an idea that it can be done this way.

  = simple_form_for(@post) do |f|
    .row.pt-4
      .col-lg-3  
        -if f.object.errors[:base].present?
          .alert.alert-danger
            %ul 
              %li= f.error_notification message: f.object.errors[:base].to_sentence

The problem I have is that the first error is listing it correctly, but the others are not.

example: enter image description here

example with more errors enter image description here

it should be displayed every error with a bullet point

Upvotes: 0

Views: 320

Answers (1)

Chiperific
Chiperific

Reputation: 4686

You need to loop over the errors:

= simple_form_for(@post) do |f|
    .row.pt-4
      .col-lg-3  
        -if f.object.errors.any?
          .alert.alert-danger
            %ul
              = f.object.errors.each do |error| 
                %li= f.error_notification message: error.message

Upvotes: 1

Related Questions