Ruby on Rails
Monday, January 29, 2018
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| %>
On Mon, Jan 29, 2018, at 17:31, Ivo Döhler wrote:
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 @articleelserender :editendendthe 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.4Thx 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