This site is about programming(mostly) things I either do or am learning.
15 Mar 2018 | | rails
Rails-ujs was formerly JQuery-ujs but the JQuery dependency was removed hence the name change.
Rails 5.1 added form_with form helper method that provides capabilities of form_for and form_tag. Rails unified form_for and form_tag that provide similar interfaces to generate forms with form_with helper.
Now we can use form_with for both model and non-model based forms.
If your application uses rails-ujs, the form will be submitted via ajax, and it listens on following events.
ajax:success : This event is called when Ajax response is success.
ajax:error : This event is called when Ajax response is failure.
Event can be binded on form as given below.
$(document).on('ajax:success', '#new_user', function(e) {
console.log('form_with: successfully submitted form via ajax');
});
$(document).on('ajax:error', '#new_user', function(e) {
console.log('form_with: error submitting form via ajax');
});