6

I configured my rails app to use a different asset prefix, by editing the file conf/application.rb.

+config.assets.prefix = '/wrapper/thing'

It works for asset pipeline but when I try to use it on my view.

<%= asset_path('milk.png') %>

It still outputs "/assets/milk.png" instead of "/wrapper/thing/milk.png".

Am I missing something?

1 Answer 1

7

You should double-check your file names as there was a report of a similar bug which turned out to be a typo.

Basically what happens in Rails 4 is that the prefix is omitted if the asset doesn't exist.

You can test the behavior in the Rails Console as they demonstrate on the thread: https://github.com/rails/rails/issues/15873

$ rails new path-test
$ touch app/assets/images/hello.png
$ rails c
Loading development environment (Rails 4.1.1)
>> Rails.application.config.assets.prefix
=> "/assets"
>> ActionController::Base.helpers.asset_path "hello.png"
=> "/assets/hello.png"
>> ActionController::Base.helpers.asset_path "foo.png"
=> "/foo.png"

FYI, you will likely get a quicker response to Rails questions over on Stackoverflow where there is much larger Rails community: https://stackoverflow.com/questions/tagged/ruby-on-rails

Hope this helps

1
  • 1
    Thank @wayne-phipps this answers my question "Basically what happens in Rails 4 is that the prefix is omitted if the asset doesn't exist." Also I didn't notice I thought I was on stackoverflow ;/ sorry. Oct 22, 2014 at 21:50

Not the answer you're looking for? Browse other questions tagged .