Basic Opal Rails 7 Example
Rails 7 recently came out with simplified defaults, including defaulting back to Sprockets.
You may follow these instructions to get a Hello, World! Opal example running in Rails 7:
Advanced Opal Rails 7 Example
It will be an animated baseball card creation application that simply takes a player name, team, and position, and renders a baseball card live while information is typed into a WYSIWYG form.
The form looks up random player animated gifs on Giphy. If you do not like the randomly selected photo, you can click the "Another Player Image" button to change it. Otherwise, the form also adds an image for the selected baseball team logo and it edits an SVG element live that represents the player position (e.g. if the player is a 1st-base position player, that part of the SVG lights up yellow). Here is how the "New baseball card" form looks like:
The code solution is included below (note that since it is just a demo, I mostly embedded CSS in the elements in the `_baseball_card.html.erb` partial).
Opal jQuery Example
The same app should continue working, but with more maintainable Opal jQuery Ruby code!
A canonical version of the project is available at GitHub:
Also, hosted on Heroku: