Rails Request.JS encapsulates the logic to send by default some headers that are required by rails applications like the X-CSRF-Token.
- Add the
requestjs-railsgem to your Gemfile:gem 'requestjs-rails' - Run
./bin/bundle install. - Run
./bin/rails requestjs:install
If using the asset pipeline to manage JavaScript, the last command will:
- Append
import "@rails/request.js"to yourapp/assets/javascripts/application.jsentrypoint.
Make sure you've already installed importmap-rails and that it's referenced before requestjs-rails in your Gemfile.
If using Webpacker to manage JavaScript, the last command will:
- Install the Request.JS NPM package.
With the installation done check the documentation in the Rails Request.JS repository.
Request.JS for Rails is released under the MIT License.