Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nodrog opened this issue Nov 16, 2011 · 12 comments
Closed

Comments

@nodrog
Copy link

nodrog commented Nov 16, 2011

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.

https://github.com/nodrog/asset-pipeline-issue

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...

@stellard
Copy link

+1

I cant get this working either

@relf
Copy link

relf commented Nov 16, 2011

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

@nodrog
Copy link
Author

nodrog commented Nov 17, 2011

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.

https://github.com/nodrog/rails/tree/asset_path_conflict

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

@mbiczysko
Copy link

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.

@TheMikeSanto
Copy link

Also having troubles with this issue.

@docunext
Copy link

docunext commented Dec 1, 2011

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.

@nodrog
Copy link
Author

nodrog commented Dec 1, 2011

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.

@guilleiguaran
Copy link
Member

This still being a issue in 3.1.3?

@nodrog
Copy link
Author

nodrog commented Dec 11, 2011

i have not had a chance to try it

@mbiczysko
Copy link

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

@guilleiguaran
Copy link
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

@nodrog
Copy link
Author

nodrog commented Jan 20, 2012

thanks guilleiguran you are a star...

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

No branches or pull requests

6 participants