Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form with remote: true still send as HTML #174

Open
Merff opened this issue Dec 29, 2016 · 13 comments
Open

Form with remote: true still send as HTML #174

Merff opened this issue Dec 29, 2016 · 13 comments

Comments

@Merff
Copy link

Merff commented Dec 29, 2016

Rails 5 and carrierwave
I add:

gem 'remotipart', '~> 1.3.1'

and

//= require jquery.remotipart

I have the form:

= simple_form_for state, remote: true do |f|
  = f.input :wsr

The output for that form:

<form class="simple_form" novalidate="novalidate" id="edit_odc_state_73" enctype="multipart/form-data" action="/odc_states/73" accept-charset="UTF-8" data-remote="true" method="post">

But when i submit form:

Started PATCH "/odc_states/73" for 127.0.0.1 at 2016-12-29 16:02:56 +0700
Processing by OdcStatesController#update as HTML
  Parameters: {"utf8"=>"✓", "odc_state"=>{"wsr"=>#<ActionDispatch::Http::UploadedFile:0x007f67ba393338 @tempfile=#<Tempfile:/tmp/RackMultipart20161229-10725-1r3sn5z.txt>, @original_filename="test1.txt", @content_type="text/plain", @headers="Content-Disposition: form-data; name=\"odc_state[wsr]\"; filename=\"test1.txt\"\r\nContent-Type: text/plain\r\n">}, "id"=>"73"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)
  
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):

Why send as HTML, any ideas ?

@stereodenis
Copy link

@Merff do you have = csrf_meta_tags in your layout?

@Merff
Copy link
Author

Merff commented Jan 17, 2017

@stereodenis yes, I have

@stereodenis
Copy link

@Merff but your form is not submitted by remotipart (it has no remotipart params)

@Merff
Copy link
Author

Merff commented Jan 18, 2017

@stereodenis why? how I can add this params?

@invisiwill
Copy link

I'm having this same issue.

@Merff
Copy link
Author

Merff commented Mar 9, 2017

In my case the error was from jquery handler - "onchange"

@pedroadame
Copy link

I'm facing the same problem. Any solution? @stereodenis

@Merff
Copy link
Author

Merff commented Apr 3, 2017

@pedroadame check jquery handlers, in my case problem was from handler.

@pedroadame
Copy link

@Merff I'm not using any jQuery handler. My form is displayed via AJAX in a vex (in case you don't know, is a JS modal library) dialog, and submitted via AJAX from there. Suddenly it started saying 'Invalid authenticity token', which was fixed by adding authenticity_token: true to the form_for, but it always process the request as HTML, then crashes on the respond_to :js line.

Currently I'm building the form again from scratch just to see what broken it, because I cannot figure out.

@pedroadame
Copy link

@Merff I solved my issue, it turned out to be something with vex. Stopped using it, it worked flawlessly.

@vkeziah
Copy link

vkeziah commented Aug 25, 2017

I am having the same issue any solution @JangoSteve ?

@matissg
Copy link

matissg commented Oct 16, 2017

@vkeziah I ended up using ufujs-rails gem. Works like charm in my case with AJAX modal and file upload. In addition I use this approach to generate unique file names.

@mcfoton
Copy link

mcfoton commented Jul 3, 2018

Rails 5.2.0 here. It helped me to switch from
//= require rails_ujs
to
//= require jquery_ujs
but I'm far from being sure that's a proper way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants