News for hackers. Stuff that matters.
Re:Web apps built with Ruby on Rails by douchescript on Friday January 10, 2025 @12:18PM (#42657616)
What’s the best way to use JavaScript on rails these days?

I’ve been using rails for over 20 years and still love it but the JavaScript story has always been in flux in bad ways. I don’t like the turbo stuff or stimulus. Basically just want to be able to add some nice charts, and some enhancements like confirmation for links. Basically just build admins with it so the caching for partial html just isn’t part of the game. Looked at upgrading to rails 8 now but the javascript in last version of rails was fragmented and complicated, so looking to find a good way to do it in a standard way now, hopefully next version of rail’s doesn’t change everything again.

Re:Web apps built with Ruby on Rails by breckenedge on Friday January 10, 2025 @01:02PM (#42658070)
The fragmentation is more an implication of the ever changing landscape of JS frameworks and build tools than Rails.

For me, Stimulus adds just the right amount of structure over Vanilla JS.

And Turbo/Hotwire feels like building skyscrapers with wood vs. steel.

Re:Web apps built with Ruby on Rails by mardifoufs on Friday January 10, 2025 @11:57PM (#42663421)
What? No, it's just rails that has changed how it handles JS, or at least the recommended way to handle JS very often throughout the year. It's weird to blame it on the JavaScript ecosystem. Like I can't figure out what changes in the JS ecosystem you are referring to exactly.
Re:Web apps built with Ruby on Rails by breckenedge on Saturday January 11, 2025 @01:58PM (#42668099)
Rails has changed it four times in 12 years:

* Prototype

* Asset pipeline

* Webpacker

* Importmaps

Re:Web apps built with Ruby on Rails by douchescript on Monday January 13, 2025 @06:26AM (#42682334)
There was also the coffeescript romance, that was brief. But maybe earlier.
Re:Web apps built with Ruby on Rails by itsthecourier on Friday January 10, 2025 @12:23PM (#42657678)
just use importmaps

https://guides.rubyonrails.org/working_with_javascript_in_ra...

- Adding npm Packages with importmap-rails To add new packages to your import map-powered application, run the bin/importmap pin command from your terminal:

$ bin/importmap pin react react-dom

Then, import the package into application.js as usual:

import ReactDOM from "react-dom"

Re:Web apps built with Ruby on Rails by douchescript on Friday January 10, 2025 @01:41PM (#42658596)
But how do you integrate and turn on at a specific page/controller view? Look for a specific dom id?
Re:Web apps built with Ruby on Rails by douchescript on Monday January 13, 2025 @06:30AM (#42682357)
It would be a valid thing if there was a documented way to convert a generic node package to import map. Not much stuff in that importmap ecosystem - seems doa.