Like so many others here I also just registered for the forums just to add another comment to this thread. Long time Rails developer, but have done very little front-end Rails work for a few years focusing on API work. Started adding some front-end to a Rails 7 app and what a minefield with the javascript builders, and bundlers and what not. Need this library, that doesn’t work with importmaps, so you need to use esbuild, which break these other things. I understand it’s necessary for front-end work, just wish it was a little less messy and there was just one way. Love Rails, and I know this is mostly because I have very little understanding of the different packagers, and bundlers, but do miss when you could get an app going and be productive right away.
Hi, could you explain what you figured to understand about the app/assets/javascripts vs app/javascripts ? I’ve got both and I can’t get the asset pipeline to work. When I got everything woking in dev, I found out that assets:precompile generates a blank js file that breaks everything.
PS: I agree with how horrendous it is for anyone to understand what is going on and how things work in RoR
Did you generate a new Rails app?
As far as I understand it to be over time
/app/assets/javascripts was the location for Sprockets bundled javascript (JS Sprinkles) Anything in app/assets is bundled according to the app/assets/config/manifest.js file.
/app/javascript is the new location for javascript module files (like when using jsbuild, webpack, etc) This can be any random JS file, stimulus controllers, actioncable files, whatever. How things are built in there would be controlled by your JS bundler. In my case I use webpack so my config is defined in webpack.config.js in the project root. Other bundlers may be different.
I’ve never used Propshaft so not sure how that changes anything I mentioned above
fwiw:
I only have app/javascript It contains application.js and my folder custom which contains my main.js
bin/importmap.rb gets the line:
pin_all_from "app/javascript/custom", under : "custom"
and app/javascript/application.js gets the line:
import "custom/main";
that works for me and assets:precompile
yes I started with a new Rails app and excluded most parts:
rails new Intra7 --css bootstrap --skip-action-mailer --skip action-mailbox --skip-action-text --skip-active-job --skip-active-storage --skip-action-cable --skip-hotwire --database=sqlserver
just to find in the gemfile
gem "rails", "~> 7.0.8"`
which includes all modules
But a simple form with remote: true
is not using ajax but requesting text/html. So I added gem "rails-ujs"
to the Gemfile and import Rails from "@rails/ujs"
to javascript/application.js. And now I’m stuck as it still is not working.
So now looking at the documentation: https://guides.rubyonrails.org/v7.0/asset_pipeline.html
Chapter 2.4 is talking about the manifest file app/assets/javascripts/application.js
Looking at the new empty Rails app, there is no folder app/assets/javascripts
, but there is a builds/application.js
and a javascript/application.js
(The purpose of the builds folder is not mentioned in the docs)
Adding something to javascript/application.js
does nothing at all. After some googeling I found that I have to run yarn build
, but wtf is yarn? It is not mentioned in the asset_pipeline.html but in webpacker.html. But when I ran rails new
it told me that it will use importmap as default:
#Choose JavaScript approach [options: importmap (default), webpack, esbuild, rollup]
Very confusing…
So I spend a whole day trying to migrate a simple rails app with 4 controllers and without any javascript, to Rails 7.
Yes I am not a super duper rails developer, but when I’ve created this little app 10 years ago it was fun to work with Rails, but today…
I’ve been using Rails since v1. Am currently spending many months upgrading a project from v6 to v7.1 and am at the point of walking away from it.
The front end interfacing with GoogleMaps api, Lightbox2, etc is causing so much grief to get working in a stable and consistent fashion it’s becoming a joke.
It struck me that with current Rails if you’ve been following the process of it evolving from one version to another then you’ve got a good chance of being able to understand how and why things are going in that direction. But as a jobbing RoR developer who simply wants to produce applications using the latest version it’s nigh on impossible to find a straightforward guide to doing things. I seem to spend hours going from discussion to discussion forum trying to understand what I simply need to do to get it all working together. “well you could use this but then again you could use that but its slower than this and anyway it’s all going to be replaced next with this…” and on it goes.
Anyway moan over - back to swearing at the screen simply because a Googlemap won’t show because I’m using v2 but should be v3 yet no where in any code can I see where it specifies the version to load - infuriating.
I found this Rails World 2023 talk by Breno really great in discussing the evolution of Rails assets integration over the years. Def worth watching even if you’re a Rails pro
I have to agree with @hadmut and no matter how much others try to belittle the truths he’s pointed out, the reality still stands. I mysefl have spent so much time (I do not want to say wasted, but rather building castles on an unknown foundation). If you do not come from money and big teams (like getting paid to play around and work). If you’re a fullstack freelancer, and build your own projects from functional requirements to get paid. Yeah this is my reality and for hundreds of thousands of others.
Smart people will always come and tell you this and that, quickly, and even belittle legitimate feedback. At one point I was so so upset for not having control over my time management, having to dig deep and make experiments to get basics to work. Even simple things like integrating dropzone (a simple drag and drop) worked perfectly fine up to rails 6.
Overall rails was fun, and now …maybe. Just remember most of us know this, and unless the documentation is improved we will always feel this insecurity, and tbh rails is a breath of fresh air, for those of us, who are solo / small teams who build projects to get paid.
I hope you don’t take this as judgement and pay attention at the purpose of rails. It’s to make a devs life easier and not time inefficient.