News for hackers. Stuff that matters.
Re:Alpine.js for Ruby on Rails Developers: Simplifying Front... by Alifatisk on Thursday August 15, 2024 @06:51AM (#41254621)
But how would Alpine communicate with the Rails backend? Do I have to manually map the routes url between FE and BE?
Re:Alpine.js for Ruby on Rails Developers: Simplifying Front... by zoidb on Thursday August 15, 2024 @07:02AM (#41254683)
It doesn't help to share state between the front and the backend. What apline.js really excels at is managing state on the frontend itself, especially for UI. For example, if you need to click on one thing that shows another thing, or you need to swap out ui elements it helps to make that easier.

For communicating the backend through using an api, or issuing async get/post or form submissions that is done pretty much the same as you would do it using html or javascript.

Re:Alpine.js for Ruby on Rails Developers: Simplifying Front... by halfcat on Thursday August 15, 2024 @10:55AM (#41256854)
Yes, and Alpine would often be paired with HTMX to handle client/server interactions.

And Rails has their own flavor of this with Hotwire/Turbo.

Re:Alpine.js for Ruby on Rails Developers: Simplifying Front... by imacrayon on Thursday August 15, 2024 @11:32AM (#41257242)
You can use https://alpine-ajax.js.org for this, or Alpine can work as an alternative to Stimulus.js in the Hotwire stack.
Re:Alpine.js for Ruby on Rails Developers: Simplifying Front... by avdept on Friday August 16, 2024 @01:38AM (#41263461)
Yeah as folks said below - Rails provides data to alpine, and alpine manages state based on initial value. But you can do regular XHR requests from alpine too, since it has regular functions which you can call