Rails - How to get file path (not url) for assets?

I have a weekly generator that zips up some files. Some of them are assets in app/assets/images/xxx.xxx , some of them are loaded through Paperclip and in public/system/env...

The file paths that I run after the app , without /images/ or public .

I will get something like /assets/some.png or /system/production/xyz/some.jpg , and they will be served normally as the path to the URL, but I want to collect them into a file.

How can I get the path to the resource file?


I think this is an easier way to explain this.

Given a string of resource URIs, how can I find and get the path to an asset file?

The URL path of the /assets/logo.png resource can be one of the files:

 public/logo.png public/assets/logo.png app/assets/images/logo.png 
+5
source share
1 answer

Rails.root gives you an absolute path to your project root. (It returns a Pathname object)

Then you can do something like this:

 Rails.root.join("some_dir1", "some_dir2", "some_file") 

So, to get the file path inside public / assets :

 Rails.root.join("public", "assets", "file.jpg") 
0
source

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


All Articles