Rails 3.1.1 - Asset Pipeline - asset.prefix not working with resource :assets #3643

nodrog opened this Issue Nov 16, 2011 · 12 comments

7 participants


I am having an issue with the asset pipeline, I already have a resource / controller called assets. So i have changed assets.prefix option to "/externals".

config.assets.prefix = '/externals'

This simple dose not work unless i remove:

resources: assets

Then all works as expected.

I am not sure how to write a test to prove this but i have created a app to showcase it.


If you run the app, and visit '/products' all will work, then go to the routes file and change the variable create_bug to true.

We have looked into https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/helpers/rails_helper.rb, and then added a debugger to the asset_path method.

This method is not called, if you but a debugger in the javascript_include_tag method. And run method(:asset_path).source_location, it tells you it is calling the method from default routes not from the sprockets helper.

Any help would be greatly appreciated...



I cant get this working either


I also get this issue on an existing application which uses an Asset resource.
It seems to be related to 2684f17


relf the issue seems to be that each person that comes across this issue fixes it from there point of view. The underlying issue is that asset_path is wrong when you add your own route for assets.

I have forked rails to show what i am going to use for the time being.


I dont think that the sprockets helper should have a asset_path in it, so i have changed it to pipeline_path and defaulted the value of the config.asset.prefix to 'assets'.

The only disadvantage to this is that you can no longer use 'asset_path' to link to your assets. But in the main it dose not seem that this should be done, the other helpers are better 'image_path', 'javascript_include_tag' etc.

I am not sure how else to fix it, as depending on if you use the prefix or not then asset_path will come from your routes and cause an issue or come from the sprockets helper and cause problems.

thoughts from people much cleverer than me would be much appreciated... for the time being i will use my fork


Seems to be same issue I'm experiencing. Fork above solve the problem, but could someone actually validate the fix is that the correct way it should be done.


Also having troubles with this issue.


Your fork helped me figure out what's wrong here. Its a tough one!

My gut suggests that there should be an option to namespace the asset pipeline, or simply give the asset_path method a prefix, or to simply define it by a configuration setting.

FYI - another alternative is to use :as => 'notassets' or something in routes.rb so that the helper methods don't collide. Of course the helper methods to your objects will not be asset_path, but imho that's easier to manage.


thanks docunext, yes it seems right now there are not quite enough options to make it work as intended.

I had not thought of using the :as option, very good idea, will work for now, but people are going to keep hitting this issue, as Asset i would think is a particularly common name to use in an app! pipeline might have been better, although a friend has worked on a oil pipeline leak application so a totally safe name would not be practical.

Ruby on Rails member

This still being a issue in 3.1.3?


i have not had a chance to try it


Tested its still not work in 3.1.3 same issues.
Any thoughts ?.

Ruby on Rails member

I just tested using rails from 3-1-stable branch, this is fixed with a2f4ef1 and will work fine in Rails 3.1.4 and 3.2.0


thanks guilleiguran you are a star...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment