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

Wrong HTTP method after updating from 19.1.1 to 20.0.0 #867

Closed
1 task done
lucasfais opened this issue Dec 22, 2021 · 5 comments · Fixed by #868
Closed
1 task done

Wrong HTTP method after updating from 19.1.1 to 20.0.0 #867

lucasfais opened this issue Dec 22, 2021 · 5 comments · Fixed by #868
Milestone

Comments

@lucasfais
Copy link

Steps to reproduce

We have a rails app using client_side_validations and we had problems updating it from to 19.1.1 to 20.0.0.

A few forms using client_side_validations are issuing the request with the wrong HTTP method, resulting in a 404.

For example, action defined as PATCH, but POST is used.

Our forms are defined with simple_form_for and we are specifying the correct http method via method: argument.

I noticed that, on 20.0.0, <input type="hidden" name="_method" value="patch"> is missing from the HTML, so rails doesn't know it is a PATCH method.

Could this be related to #862 mentioned in the CHANGELOG? Is that something I should adjust on my code?

Expected behavior

Requests coming from JS should use the correct HTTP method.

Actual behavior

Requests coming from JS are using a wrong HTTP method.

System configuration

Rails version: 6.1.4.4

Ruby version: 2.7.4

Client Side Validations version: 20.0.0

Code snippet from your model of the validations

Not relevant; it happens regardless of which validations are being used

The whole form code from your template

= simple_form_for @model, url: my_action_path, remote: true, validate: true, method: :patch do |f|

The resulting HTML

Regular form element, but <input type="hidden" name="_method" value="patch"> is missing.

Browser's development console output

  • I confirm that my browser's development console output does not contain errors, expect the 404 error mentioned

Additional JavaScript Libraries

n/a

Repository demostrating the issue

n/a

@tagliala
Copy link
Contributor

tagliala commented Dec 22, 2021

Hi,

Thanks for this report, I can confirm.

I've identified the issue and I do not recommend to use CSV with Rails 7.

There is something wrong and I do not have a clear clue on both how to fix this behavior and why the tests didn't find the bug.

The problem is here:

input_tag: form_helper.class.field_error_proc.call(%(<span id="input_tag"></span>), Struct.new(:error_message, :tag_id).new([], '')),
label_tag: form_helper.class.field_error_proc.call(%(<label id="label_tag"></label>), Struct.new(:error_message, :tag_id).new([], ''))

On localhost, I cannot even add validate: true to a basic form_with and I get

undefined method `content_tag' for ActionView::Base:Class

without a backtrace

As a workaround, if CSV works for your use case, please manually add the hidden field with the method to the form element pass the method in html options:

= simple_form_for @model, url: my_action_path, remote: true, validate: true, html: { method: :patch } do |f|

PR (and a failing spec) are very welcomed

tagliala added a commit that referenced this issue Dec 22, 2021
This change is not needed in Rails 7 but on older versions

Fix: #867
Ref: rails/rails#43421
@tagliala tagliala added this to the 20.0.1 milestone Dec 22, 2021
@tagliala
Copy link
Contributor

20.0.1 released, thanks

@lucasfais
Copy link
Author

Awesome. I'm actually using rails 6.1.4.4. I'll test with the new gem version. Thanks!

@lucasfais
Copy link
Author

I can confirm 20.0.1 fixes the issue with rails 6.1.4.4. Thank you!

@tagliala
Copy link
Contributor

I've splitted the other issue I've found while investigating this into #869

I've also understood why the tests pass. The other issue is related to Rails 7, so it should not be a problem on 6.1

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

Successfully merging a pull request may close this issue.

2 participants