Rails - resource pipeline - identifying a resource by catalog

Say in vendor/assets I have two subdirectories: /alpha and /beta , each of which has a file called temp.jpg . In my opinion, the GET request is made for /assets/temp.jpg , and I am sure that the one served from the alpha directory. But how can I distinguish them from two? I think this can be done with the asset_url , but I'm not quite sure if anyone can advise, that would be great.

+6
source share
2 answers

From the manual:


You can view the search path by checking Rails.application.config.assets.paths in the Rails console.

Additional (fully qualified) paths can be added to the pipeline in config / application.rb. For instance:

 config.assets.paths << Rails.root.join("app", "assets", "flash") 

Asterisks will also view the paths specified in config.assets.paths, which includes standard application paths and any path added using Rails engines.

Images can also be organized into subdirectories, if required, and can be accessed by specifying the directory name in the tag:

 <%= image_tag "icons/rails.png" %> 

If you are using the asset pipeline, I'm not sure which of your images will be provided with a link that does not provide a URL, if any. If someone ships, this will be related to the order in which Sprockets recursively read these directories. If he reads them in alpha order, then a "beta image" will be displayed. Or else it will be random, I'm not sure how Sprockets read directories.

You will be better off posting an explicit path there. If you are doing some kind of test, for example, if you want beta images to appear, I would recommend some kind of parameterized approach so that you can switch to alpha or beta on your way.

+1
source

Check http://guides.rubyonrails.org/asset_pipeline.html#asset-organization and try running Rails.application.config.assets.paths in the Rails console to debug the loading path of your resources.

0
source

Source: https://habr.com/ru/post/911098/


All Articles