mbajur
mbajur

Reputation: 4474

image_path() generates wrong image path for engine assets

I'm using rails4 + ruby2 and trying to create a rails engine. This engine has a separated assets dir with it's own stylesheets (sass), javascripts and images.

The thing is, image_path() sass helper generates a wrong image path. Let's say my engine is called 'Admin'. There is a image file called arrow.png in /admin/app/assets/images/admin/arrow.png.

If, in application.css.sass i'm gonna use background: url(image_path('arrow.png')), it will generate a following url: /assets/arrow.png which will not work. The proper url is /assets/admin/arrow.png.

There are probably two possible solutions right now:

  1. Move all /admin/app/assets/admin/images/* to /admin/app/assets/images, or
  2. prefix all image names in image_path() method with engine name which gives me image_path('admin/arrow.png').

Are there any other, better, ways to handle this thing?

Upvotes: 1

Views: 1312

Answers (1)

Ranjithkumar Ravi
Ranjithkumar Ravi

Reputation: 3462

The best solution is:

image_path('admin/arrow.png') OR asset_path('admin/arrow.png')

As Subfolders are also merged into public/assets. That means both app/assets/javascripts/subfolder/* and app/assets/stylesheets/subfolder/* now live in public/assets/subfolder/*

Upvotes: 2

Related Questions