Telling Rails to look somewhere other than public/assets for assets

2/28/2019

I'm trying to deploy an admin dashboard on top of a Rails API. Currently, it's Ingress service is setup at site.com/api/admin, and Rails is searching for the assets at site.com/assets, so it doesn't find them.

How can I tell Rails to look for the assets at site.com/api/assets/admin.css? I've tried using config.assets.prefix = '/api/', but that seems to just change the directory the assets are precompiled to to public/api/assets, but in application.html.erb, the stylesheet link tag is still public/assets/admin.css, resulting in 404 errors for all assets.

-- domi91c
asset-pipeline
kubernetes-ingress
ruby-on-rails

2 Answers

2/28/2019

You need to add the folder's path into the asset pipeline. You can do it by going to config/initializers/assets.rb and adding the following line:

Rails.application.config.assets.paths << Rails.root.join('my', 'folder', 'path')

Or, in this case:

Rails.application.config.assets.paths << Rails.root.join('app', 'public', 'api', 'assets')
-- Giorgio Zanni
Source: StackOverflow

2/28/2019

After days of troubleshooting, I tried setting config.relative_url_root to '/api', and it's now finally working.

-- domi91c
Source: StackOverflow