Yes. I've already experimented with that exact idea successfully on top of Ruby on Rails in this project:
https://github.com/AndyObtiva/glimmer-dsl-opal

That said, you have two options:
- Opal Ruby (https://opalrb.com/): compiles Ruby to JavaScript, thus resulting in a small footprint (just kilobytes) by only including what is needed of Ruby for a specific app's code. It supports Ruby 3.2 & Ruby wrappers for JavaScript APIs like the DOM.
- WASM Ruby (https://github.com/ruby/ruby.wasm): compiles Ruby to Wasm, thus resulting in a heavy footprint (megabytes not kilobytes last I heard). It supports Ruby 3.2 & Ruby wrappers for JavaScript APIs like the DOM.

Check out this try-ruby playground that lets you try both options (Opal & WASM):
https://try.ruby-lang.org/playground/

My experiment (mentioned above) was done in Opal Ruby as it is the lighter-weight solution.

What would push this idea forward though is to contribute Ruby frontend support to Rails as a very simple configuration option to enable it out of the box effortlessly, or better yet, make it a default. From that point forward, Ruby developers could become accustomed to writing Ruby code on both the frontend and backend (including sharing of models with non-sensitive data), thus improving productivity and maintainbility immensely.

Whoever makes the effort to integrate frontend Ruby into Rails as a basic option would greatly help the Ruby community thrive through simpler more maintainable code on the frontend in addition to the backend. 

By the way, I've already documented how to get started with Opal Ruby and Rails 7 with this blog post:
https://andymaleh.blogspot.com/2022/01/using-opal-ruby-with-rails-7.html

If anyone wants to collaborate on making the use of Ruby in the frontend even simpler to activate from a Rails app (e.g. by including commented gem lines and post install instructions to help Rubyists discover frontend Ruby options), I'd be happy to contribute some of my time for this.

Ruby WASM requires megabytes for the initial load of the site as far as I know, so it can be put on hold for a little while for now, and tackled a bit later when it's become more mature.

Ruby WASM might need to be improved first to figure out what parts of Ruby are used by application code so that it produces a much smaller downloadable during compilation instead of precompiling everything.

To be frank, this problem (Ruby in the frontend) should have been fully solved back in 2014 when Opal Ruby was still new. It should have become a default standard in the Rails framework back then. That would have helped Ruby leapfrog all the JS technologies that came out since then, rendering them all useless.

Businesses could profit greatly from the productivity benefits of having a generally unified codebase between the frontend and backend just like how that was always the case in the 90's with network-enabled desktop applications. 

In any case, with Matz (creator of Ruby) getting excited about Ruby in the browser and embracing the idea of replacing all JavaScript frontend code with Ruby, as mentioned by him during RubyConf 2022's keynote speech (which I attended and presented at), the Ruby community is now more than ready for having Ruby in the browser be a common standard in web application frameworks, whether it's Rails, Sinatra, Hanami, or Roda.

Andy Maleh

On Thu, Feb 2, 2023 at 3:13 PM lizhongyou2013--- via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:
Just an idea: Can we use the latest wasm technology to make ruby code almost completely replace JavaScript (only a few calls like Document.getElementById remain, of course they will also be wrapped in ruby). We can even replace html and css, as long as a part of the code runs before going online, and html and css are generated. In this way, we have both the front end and the back end just like node. Although this is just a guess, if it is successfully implemented, we can get rid of the inelegant JavaScript, and it is also an impact on the market, bringing Ruby to more people. Disclaimer again: the above is just my immature conjecture, if there are any omissions, please accept it.
 ______________________________________________
 ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org
 To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org
 ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org/


--