Neon Tsunami

Rails UJS outside the asset pipeline/with modules

July 18, 2017

With Rails 5.1 the team replaced the great jquery-ujs library with rails-ujs - the same feature set implemented without jQuery and rather using standalone Javascript. It's a welcome change, removing a dependency that most people are probably happy to get rid of by now.

However, if you try and load it up outside the Rails asset pipeline it's not as simple as //= require rails-ujs. When you use the module version of it you'll need to first import it, then start it. So, run yarn install rails-ujs to add the dependency and then boot it up in your app.

import Rails from 'rails-ujs';

Rails.start();

A blog about Laravel & Rails, written by Dwight Watson.