Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

webpacker - Rails Scaffolds not submitting form (form stuck on new) caused by ujs

My project's server-side scaffold forms will not redirect to the next page. (from new->show with flash message). Although the content from the form is saved and a new record saved. (not sure how?)

When i comment out the lines, in application.js in works as normal, submits, redirects to show

import Rails from "@rails/ujs"
Rails.start() 

form code is

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

but form has

data-remote=true

So it looks like trying to do ajax with default scaffold code, how can i prevent this?

question from:https://stackoverflow.com/questions/65869234/rails-scaffolds-not-submitting-form-form-stuck-on-new-caused-by-ujs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

(assuming you are using rails 6.0 where by default form submits are remote and unobtrusive XHRs... in rails 6.1 this default was reversed)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...