4

(Been looking for this for ages over internet...).

Been working with very old npm packages recently and seems that they cannot be loaded properly within Rails-6 (I know I could create a question by each cases, but I'd like to learn to handle this myself since every time it is for a different reason). I'd like (as for debugs and in development mode only) to display the list of available all assets, including js, css, images, and anything else available at public level (the client could load). So it should be a set of compiled assets ?

Similarly to http://localhost:3000/rails/mailers like http://localhost:3000/rails/assets ?

Displaying the list of all available assets (prior compilation, also for debug intents) could also be great.

Hellfar
  • 393
  • 2
  • 17
  • I don't know such function but you can access files in a folder as explained here : https://stackoverflow.com/questions/1755665/get-names-of-all-files-from-a-folder-with-ruby also if you have ever compiled your assets there is the manifest file in /public/assets which holds all public assets references. Also maybe parsing `assets.rb` file if you use sprockets. – Maxence Nov 14 '21 at 15:11

2 Answers2

4

This might do what you want:

Rails.application.assets.each_file do | pathname |
  # ...
end

This will enumerate every file of which Sprockets is aware. You can run that at rails c or build a simple controller to dump the list into a view if you prefer. For more information, see https://stackoverflow.com/a/11005361.

If you're not using Sprockets (e.g. a newer Webpacker-based application) then, obviously, you'll need a different solution.

Andrew Hodgkinson
  • 4,379
  • 3
  • 33
  • 43
-1

You can run rails assets:reveal and see all the available assets:

$ rails assets:reveal
application.js
application.js.map
application.css
application.scss
...

To view the full path, use rails assets:reveal:full:

$ rails assets:reveal:full
/home/{REDACTED}/app/assets/builds/application.js
/home/{REDACTED}/app/assets/builds/application.js.map
/home/{REDACTED}/app/assets/builds/application.css
/home/{REDACTED}/app/assets/stylesheets/application.scss
...
Ashvith Shetty
  • 90
  • 2
  • 11
Dorian
  • 7,749
  • 4
  • 38
  • 57