This is an example of how to implement a "widget" with Ruby on Rails.
The widget is added to a webpage with the example on test_widget.html.erb
:
<div id="my-widget"></div>
<script src="https://my-domain.com/widget.js" type="text/javascript"></script>
This will request the JS code from the server, ensuring you can change it without having to update the webpage were the widget is.
The JS code from the server will load necessary dependency and create the iframe where the content will be placed.
The iframe's url point to the server that will respond with the desired HTML.