Hi,
I just ported two rails apps from rails 5.2 to rails 7.0, and it caused me some headache and cost me some time to get the asset pipeline and a small ajax function (which just updates a table in a web page) working again. I had to do a lot of trial-and-error and googling other web pages. Since you ask for feedback on the guides pages, I’ll give some in order to improve the pages.
A general problem is that the pages – I admit that many docs have this problem nowadays – tends to tell “do this if you want that”, but never gives a comprehensible overview, picture of what is going on.
One thing is, that with 5.2 I had the javascript in app/assets/javascripts , while newly created and updated 7.0 apps do have app/javascripts. The Update guide does not mention this in particular.
I have not yet really understood wether app/assets/javascripts has completely been moved to app/javascripts, or whether they coexist and what’s the difference between app/javascripts/application.js and app/assets/javascripts/application.js
Working with JavaScript in Rails — Ruby on Rails Guides gives some javascript code examples, but does not mention at all, where to put them and how to include them.
I’m also not sure what is the current syntax of including things, whether
//= require rails-ujs
or
import Rails from “@rails/ujs” Rails.start()
The latter worked, but I found this on some blog page somewhere in the internet, not in the guide.
The rails guide mentions the UJS framework, but does not tell how to get this running or whether it takes additional steps to do so. It took me some hours testing and trying to figure out, why my form does not trigger the javascript to just fetch a table and replace it on the page, and instead always loaded the table as a new page, i.e. did the regular form action and not the ajax action.
On thing was that I had to learn that I had to turn turbolinks off, in order to get things work again, and that the guide was simply wrong in that detail, because it still talks about turbolinks, while rails 7 uses the newer framework turbo instead of turbolinks. Therefore, it takes a
data-turbo=“false”
attribute, and not a
data-turbolinks=“false”
as told in the guide, to turn turbo off and keep it from spoiling the ajax function. Given the fact, that turbo seems to heavily impact the page behaviour, the guide tells very little about this. And it does not tell how to get completely rid of it.
And I had to do a
yarn add @rails/ujs
and to change the application.js in order to get things running (while not yet really understanding sufficiently, what’s going on).
Similar difficulties with the asset pipeline.
Both guides do not really match rails 7, and they are not enabling a reader to understand what’s going on. As mentioned before, they are a collection of tips and tricks of the style „if you want to achieve behaviour x, then write line y into file z“, without ever explaining, what file z is, what syntax it uses, where it goes to, or – e.g. application.js – where it is, in app/assets/javascripts or app/javascripts (in both directories there is one).
For both the asset pipepline in common, and the javascript thing in particular, some overview is needed. Which parts, which files of the rails app do belong to this functionality (e.g. what role do package.json and yarn.lock play here), what are the rake/rails commands to steer that thing, and what is the meaning and syntax of all those files in that game. I see several files where I simply cannot tell whether they are relevant for the asset pipeline and javascript, or not.
E.g. it took me some time to understand, that this is done in two steps, first create things in products, and then pack them together.
And I did not get the pipeline working in development mode. Even in development mode I have to run assets:precompile to get things running. For the shere fact that I do not see a description about how things are supposed to work in development mode, and thus do not know where to start debugging.
regards