I'm trying to include a javascript file that's in my public folder in one of my views.
The filename includes a randomly generated string of characters, see "648eee49" below.
public/react-menu/static/js/main.648eee49.js
I've been trying to use a global directory call to return the path, but it's not working.
<%= javascript_include_tag "#{Dir.glob("/public/react-menu/static/js/main.*.js")}" %>
The file path is returning as http://localhost:3000/javascripts/[].js
I was able to use Dir.glob, I just needed to remove the first forward slash from the search, and remove "public" from the path string.
<%= tag.div id: 'root' %>
<%= stylesheet_link_tag Dir.glob("public/react-menu/static/css/main.*.css")[0].sub("public", "") %>
<%= javascript_include_tag Dir.glob("public/react-menu/static/js/main.*.js")[0].sub("public", "") %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With