Form validation Rails 5.1.4

Hello,

I’ve read the rails introduction and followed the examples. It was quite understandable. But the form validation didn’t work as expected.

My form begins with

<%= form_with(model: @article) do |form| %>

<% if @article.errors.any? %>

and in the class is the validation rule:

 validates :title, length: { minimum: 5 }

part of the controller:

def update

	@article = Article.find(params[:id])

	if @article.update(article_params)

		redirect_to @article

	else

		render :edit

	end

end

the problem is:

if the title is too short (for example) I can push the update-button but nothing happens. There is no reload of the page at all, no errors are shown. Is the title is long enough, the submit-button works correctly. Do I change the form_with to (scope: :article, …) then the errors are shown.

I use Rails 5.1.4

Thx for a response

form_with by default generates form which is submitted by an XHR request. This is why it seems that nothing happens, but if you look to the console output, you’ll see that form was actually submitted.

You can make form_with to submit by a standard page refresh by using ‘local’ option:

<%= form_with(model: @article, local: true) do |form| %>