rails/actionview/app/assets/javascripts
Michael Bianco 9508b4b3c3 Adding docs link to ujs readme 2021-06-28 14:55:37 -06:00
..
rails-ujs chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
MIT-LICENSE Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
README.md Adding docs link to ujs readme 2021-06-28 14:55:37 -06:00
rails-ujs.coffee Don't attach UJS form submission handlers to Turbo forms (#42476) 2021-06-15 17:31:33 +02:00

README.md

Ruby on Rails unobtrusive scripting adapter

This unobtrusive scripting support file is developed for the Ruby on Rails framework, but is not strictly tied to any specific backend. You can drop this into any application to:

  • force confirmation dialogs for various actions;
  • make non-GET requests from hyperlinks;
  • make forms or hyperlinks submit data asynchronously with Ajax;
  • have submit buttons become automatically disabled on form submit to prevent double-clicking.

These features are achieved by adding certain data attributes to your HTML markup. Documentation about the various supported data attributes is available here. In Rails, they are added by the framework's template helpers.

Optional prerequisites

Note that the data attributes this library adds are a feature of HTML5. If you're not targeting HTML5, these attributes may make your HTML to fail validation. However, this shouldn't create any issues for web browsers or other user agents.

Installation

npm

npm install @rails/ujs --save

Yarn

yarn add @rails/ujs

Ensure that .yarnclean does not include assets if you use yarn autoclean.

Usage

Asset pipeline

In a conventional Rails application that uses the asset pipeline, require rails-ujs in your application.js manifest:

//= require rails-ujs

ES2015+

If you're using the Webpacker gem or some other JavaScript bundler, add the following to your main JS file:

import Rails from "@rails/ujs"
Rails.start()

How to run tests

Run bundle exec rake ujs:server first, and then run the web tests by visiting http://localhost:4567 in your browser.

License

rails-ujs is released under the MIT License.