Reputation: 23357
I have a Rails 3.1 application.
I am deploying it via passenger to a SubURI, not to URI root. For instance, the app root is actually accessed as http://somewhere.com/application .
I have a stylesheet.css.erb in my app using the asset pipeline, that sets a background-image with
<%= asset_path 'something.gif' %>
However, when I run rake assets:precompile
, it precompiles this to /assets/something.gif
, not /application/assets/something.gif
-- because when I'm running the rake task from the command line, it doesn't yet know about the path prefix ("/application") that's going to be operative when running under Passenger at a SubURI.
What's the right way to handle this? Is there a way to tell the assets:precompile task to use a particular path prefix, because we know when precompiling that we're actually going to deploy to a path prefix?
stylesheet_link_tag 'application'
in the layout, do generate properly with the path prefix. So the asset pipeline does respect the path prefix when it's operative. The problem is clearly that when I run assets:precompile, it's got no way of knowing what the ultimate prefix is going to be, the way I'm running it. How do I tell it?)Upvotes: 2
Views: 3657
Reputation: 23357
Okay, I guess maybe I'll accept @Tigraine's to give him the karma, as he LED me to the solution.
Just setting RAILS_RELATIVE_URL_ROOT is not enough however in current released Rails 3.1.3 (it might be in master) -- it won't do anything. You need to actually monkey patch Rails to add this feature.
What I actually ended up doing is a modified version of the solution given in one of the answers he pointed to. I use alias_method_chain to monkey patch copy-and-pasting as little of existing Rails logic as possible: https://gist.github.com/1595405
@Tigraine suggests there's a fix in master, I haven't confirmed this. If so, I have no idea what release of rails it's slated for (next 3.1.x, 3.2, even later?), or exactly what form it will take (RAILS_RELATIVE_URL_ROOT)? If anyone knows the answer to these, perhaps in the future when such a version is released, please add a comment or answer.
Upvotes: 0
Reputation: 23678
This has come up before: Seems to be a limitation in Sprockets that is now merged into master: https://github.com/rails/rails/pull/2977
I guess you need to set the RAILS_RELATIVE_URL_ROOT
Sources:
Upvotes: 1