Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struggling with asset pipeline: The asset "{name}" is not present in the asset pipeline

As part of ongoing efforts to migrate a legacy app from Rails 3 to Rails 6, I'm trying to figure out the best way to move forward with assets and whatnot.

I'm struggling with the following issue, when I try to add a specific asset:

<%= image_tag 'images/shared/logos/image.svg' %>

The image is present on:

app/assets/images/shared/logos/image.svg

And yet I get the error I mentioned on the title:

The asset "images/shared/logos/image.svg" is not present in the asset pipeline.

Any advice on how to set up newer Rails to handle assets would be greatly appreciated, I'm a little confused over the whole sprockets vs webpacker thing and I'm trying to figure out what is the best way to move forward.

like image 802
Dynelight Avatar asked Oct 16 '25 15:10

Dynelight


2 Answers

The default Rails setup dosn't allow to add directories to the images folder. You could change this in the config or simply store alle images directly into the images folder.

To change in config add the following in config/application.rb

config.assets.path <<< Rails.root.join('app', 'assets', 'images', 'shared', 'logos')
like image 176
Daniel Avatar answered Oct 18 '25 10:10

Daniel


The Rails asset helpers search a set of specified asset paths (Rails.application.config.assets.paths) for assets.

I'm not sure about Rails 3, but in later versions of Rails the default search paths include specific subdirectories under app/assets (app/assets/stylesheets, app/assets/images, etc.), but not app/assets itself.

So, you can drop 'images' from the start of your relative path (in fact you need to):

<%= image_tag 'shared/logos/image.svg' %>

If your existing app has lots lots of assets defined that way, you could try putting app/assets directly to the search path by adding the following to config/initializers/assets.rb:

Rails.application.config.assets.paths << Rails.root.join('app', 'assets')

That will allow Rails to find your assets while you work through the migration.

like image 43
rmlockerd Avatar answered Oct 18 '25 11:10

rmlockerd