revalidating rails form errors

40 views Asked by At

lets say I have two validations on rails model: it is necessary to fill both of them: name and title.

validate :name, presence: true
validate :title, presence true

when i submit blank form, error will be displayed. but when i fill only one and i do the submit, still both of the errors are displayed. Am I missing something? also, my form works in turbo frame, and when I fill both of the fields, the 'post' is created. and form disappears - this is ok. but if the error is displayed, the 'post' is created but form will not disappear. any help/info/guide welcomed.

as i have no idea what is going on

1

There are 1 answers

0
user_pruser On

using

format.turbo_stream do
   render turbo_stream: turbo_stream.update('form', partial: 'posts/form', locals: { post: @post })
end

instead of turbo_stream.replace solved the issue.