Home > front end >  A way to display a list of public assets
A way to display a list of public assets

Time:11-15

(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.

CodePudding user response:

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.

CodePudding user response:

You can run rake assets:precompile and se which assets are generated

  • Related