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.