neanderslob
neanderslob

Reputation: 2703

button_to with remote: :true ends up redirecting

I'm attempting to create a button for a form that allows the user to save the entered data without redirecting/reloading or anything.

I've added a button_to to my form partial as follows:

<%= button_to "Update", incorporation_path(@incorporation), method: :post, remote: true %>

This does indeed save the data but submits the form with redirect and all.

Upon adding a render :nothing => true to the update controller method, I was simply confronted by a blank page when I clicked the button. This is particularly surprising because I'd figured that the remote: true line would prevent this.

What might be up?

Any thoughts are appreciated

Upvotes: 0

Views: 1456

Answers (1)

Yan Foto
Yan Foto

Reputation: 11388

Update

You are talking about a form! Have you set the remote: true on form_for? Because that's how you submit a form asynchronously.

Original answer

remote: true is a part of Unobtrusive scripting adapter for jQuery. As the name implies this approach is unobtrusice and will not work if JS is deactivated or the library is not loaded. So make sure that you have the following lines in your script file:

//= require jquery
//= require jquery_ujs

Upvotes: 2

Related Questions