Ruby on Rails
Monday, January 29, 2018
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
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/29836bfe-e8ce-4ecc-a1b1-c36bbbc4e599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment