DEV Community

Grzegorz Smajdor
Grzegorz Smajdor

Posted on

Ruby on Rails 7 with Ajax (axios)

Recently I was working with Ruby on Rails 7 and needed to do an API requests from javascript to my ROR backend. In the past I choose [axios](https://github.com/axios/axios) for that and still, I decided to use it (as I don't yet know Turbo).

The feature was to check if user exists in the DB from the modal.

After ./bin/importmap pin axios and building the stimulus controller I got an error in a browser:

TypeError: Cannot read properties of undefined (reading
'FormData at index.js:162:32

I started to google, and search on stackoverflow for the solution but could not find anything useful.

After few minutes ... without any success I just decided to experiment with different versions of axios and guess what...turns out that the version 0.27.2 was working as expected

After pinning the version 0.27.2
./bin/importmap pin axios@0.27.2

The AJAX request worked like charm! I'm sharing this here, as You might find it useful!

The longer read you can find on medium

All the best!
Grzegorz

Top comments (0)