Should we still use ujs

I’m still trying to understand the whole hotwire way of doing things. My application.js has these two lines:

import Rails from "@rails/ujs"


Should ujs still be used? should I keep those lines?

The reason why I’m asking this is because resetting a form, like it’s shown in the video it, doesn’t reset the disable state of a button which is set automatically by ujs I believe (am I right?). I’m trying to find a way to re-enable it with JavaScript, but I can’t find anything clean. I could disable the functionality with:

config.action_view.automatically_disable_submit_tag = false

and then re-implement it myself with stimulus.

I’m not sure which path is the right path here, the hotwire way.

1 Like

Are you trying a new project to test Hotwire or adding it to an existing project?

It’s a new project where I want to do things the hotwire way. It’s a tiny app.

Cool. Here’s how I start a new Hotwire app without webpacker.

rails new myapp --skip-javascripts

This skips webpacker, turbolinks and rails ujs.

Then add gem 'hotwire-rails' to your gemfile

bundle install
rails hotwire:install

This gives you a new rails app with a beautiful assets/javascripts folder with turbo and stimulus ready to go.

1 Like

Oh, that’s what you meant by new app. Sorry… the app exists already, it’s new in the sense that I created it less than a month ago, I don’t have a lot of code to convert.

Well if the app is very small and you don’t need webpacker, you could always create a new app as written above and regenerate your migrations etc to move your code over.

Mmmm…I say this because in this new app there isn’t even an application.js. Maybe someone else can provide a better answer for just cleaning up your current apps settings.

In new apps, I’ve been removing UJs. If you are going to use both, be aware of these incompatibilities; Document how Turbo works with each Rails UJS feature by ghiculescu · Pull Request #91 · hotwired/turbo-rails · GitHub

I’ve been removing Webpacker from projects where possible, its so much simpler to just include the js files you need, do you know if there is a recommended way to use active_storage and action_text without Webpacker ?
Or would you just switch to something like Shrine and Froala ?

There are actiontext and activestorage gems

1 Like

I’m personally keeping with Webpacker, it became the standard in the JavaScript world and I want to be able to consume JavaScript libraries in a mainstream way.

Rails-Ujs may still be helpful for handling ajax for you (adding the csrf tokens etc), it’s possible Hotwire makes ajax less important but the bigger the app gets it’s very possible you will need to do something with ajax at some point.