4

So I am currently trying to convert a Rails 5.1 backend so it will convert camelCase posts to snake_case, that way I can keep my Javascript nice consistent with camelCase.

Using the Rails 5.1 answer here, I was able to easily apply the answer from this question: What is the best way to convert all controller params from camelCase to snake_case in Rails? to get JSON posts to convert nicely to camelCase. However, this answer does not cover FormData. The answers in this question: Rails: ActionDispatch::Request.parameter_parsers for multipart/form-data do pertain to converting formdata, however the accepeted answer doesn't help with deeply transforming those keys, and the other answer is deprecated since params are no longer a hash and therefore you can't call deep_transform_keys! on params anymore.

What's the best way to go about this? Should I abandon this camelCase on the frontend and snake_case on the backend effort, or snake_case on my frontend before creating my FormData objects.

Thank you!

Colton Voege
  • 409
  • 2
  • 5
  • 12
  • It will be a constant struggle trying to force camelCase in Rails. If it's harder to do that or change your JS will be your call. snake_case has always been the ruby/rails convention, and will likely remain so. – Daniel Westendorf Nov 17 '17 at 15:21
  • @DanielWestendorf So you're saying that in you're opinion it's not worth it to write a converter from camelCase to snake_case on POST, and would be better to just leave my frontend in camelCase? – Colton Voege Nov 17 '17 at 16:34

0 Answers0