Re:Modern Front-end in Rails
by inopinatus on Friday December 08, 2017 @11:20AM
(#15879750)
The webpack integration coming in Rails 5.2 starts to do exactly what you suggest. We’ve had the beta in general use for weeks and I’d say the framework is going in the direction you want.
This article seems a bit of overengineering by comparison and isn’t representative of what’s new out-of-the-box.
Does 5.2 add anything on top of 5.1? The core team added the webpacker gem back in February this year but I haven't checked out yet what they're planning with 5.2.
Re:Modern Front-end in Rails
by inopinatus on Friday December 08, 2017 @11:20PM
(#15884268)
ActiveStorage for managing file uploads is the other big new feature.
There’s also a new secrets mechanism of dubious necessity. Seems DHH just can’t stop reinventing those.
Totally agree. You can go the .js.erb views and `$('#div_id').replaceWith('<%= escape_javascript(render partial :partial_name) %>')` route, or you can use render_to_string and put your partial HTML in JSON and replace it with frontend JS, and so on and so on. And there's also turbolinks to consider and the idempotent stuff.
It's all great, I got my way around it, but I never know if what I'm doing is considered best practice or not.
I don't understand from your comment whether you are aware that Rails 5.1 introduced generators to automatically add Vue, React and Angular (and Elm subsequently)? It sets everything up neatly and allows you to selectively incorporate reactive components where they're needed in your application, without having to go all the way to separating front and backend completely.
https://medium.com/statuscode/introducing-webpacker-7136d66c...
Rails is awesome bc it’s opinionated but the fact that it’s ruby still lets you do what you want. I think rails needs to really dedicate some effort to better generators that ask which of these modern front end approaches do you want to use and then setup the project to just work and let me get to my coding.