You’ll be able to tell because the link on dev would just be the normal or while the rails precompiled assets will be " (or whatever the latest compiled asset name is). For prod you would use "the rails way"of linking so the assets would need to be precompiled. For dev/test you would link the files just like any other basic web page. In your layouts/application.erb file just link the css and javascripts manually and - this is important - add a check for whether you’re on dev, test, or prod. If I were you I’d first go way back to basic web pages. It’s old school erbs with jQuery, bootstrap, and a few other thingss and it works well, but there are some things to keep in mind. The main rails app that I develop started in rails 4.2, then 5.0, and now 7.0.4 so I avoided all of the javascript build stuff. The differences between erb templating and newer javascript build processes can be confusing as hell if you’re totally new to rails and web dev in general. “The problem with finding beginner friendly Rails resources seems to be a lot of refer back to older ways of doing things (generally speaking, but also the asset pipeline in particular) and a lot of them lead me down rabbit holes that I often can’t tell are worth burrowing into or not.” When running rails new you would have also seen in the output what it was installing and esbuild would have been mentioned a few times there. Putting it in the global namespace can cause issues because in larger projects it can be altered or removed, or something done to it in some obscure file somewhere else, by someone else, and cause subtle/malicious bugs that can become very hard to find, or cause deeper issues that the app then begins to depend on but progressively becomes harder to maintain.Īs for how to tell it’s using esbuild, you can look in the package.json file (which is what yarn uses to manage the javascript packages used in the app) and see what it’s installed, and the app specific commands that are set up (under the scripts key). For learnings sake it’s still a good idea to practice the proper methods so we don’t get into bad habits, but brevity is also important when learning other concepts. Global namespace pollution is not inherently bad, similar to a lot of coding paradigms it’s more meant for the longevity and maintainability of an application. You can still use bootstrap in this case too, you’ll just be importing it differently (similar to how the link mentioned bringing in jQuery with a cdn). You can then take out turbo, stimulus, and sass to really bring down the complexity and not even need to us esbuild or a sass compiler. If you are just using this for a project and don’t need the complexity of a JS bundler, you can bring back UJS which is how things were done by default before. Last time I looked at the rails guides for app javascript best practices it was fairly lacking, mostly because it’s not entirely it’s responsibility to go in-depth about JS development. Rails is a very mature framework that’s been around for a long time, which is both great from a stability and feature rich perspective, but also potentially frustrating from a learning perspective because there may be a lot of outdated information. I apologise if my thoughts are scattered all over the place but that’s basically how I’m feeling right now lol. I know you said “no more global accessibility etc.”, but what are the consequences of importing the jquery (or any other javascript/css library) in the application layout as above? I realise that every view using these would have to be rendered inside application layout (which happens by default, but can be changed) but are there any other consequences? I’m guessing not being able to override styles (for css) easily might be one. When I started a new project with rails new project_name -c bootstrap does that use esbuild by default? In general, how can I tell? (This isn’t a complaint… just the situation I’m finding myself in.) The problem with finding beginner friendly Rails resources seems to be a lot of refer back to older ways of doing things (generally speaking, but also the asset pipeline in particular) and a lot of them lead me down rabbit holes that I often can’t tell are worth burrowing into or not. Actually I’m new to the whole web development thing altogether… working on a student project (with a looming deadline).
0 Comments
Leave a Reply. |