How do I add asset search paths to Sprockets based on a wildcard subdomain in rails 3.1?

Just as you did for your view path, add a before filter and append the new path to Rails.application.config.assets.paths.

Just as you did for your view path, add a before filter and append the new path to Rails.application.config.assets. Paths I got this idea while watching Railscasts #279 Understanding the Asset Pipeline.

Hmm, pretty sure changing Rails.application.config.assets. Paths will add the path on for the WHOLE application, permanently, not just for the current request. It's kind of right there in the call you are making to Rails.application.AS opposed to prepend_view_paths, which is documented to effect the current request only.

So the OP question is if there's something similar you can do for asset_paths... but Rails. Application ain't it.It's possible looking at the code for prepend_view_paths could give you an idea of how to hack it in yourself though. – jrochkind Sep 30 at 12:55 Yea.

I think you're right. – pedz Oct 2 at 14:55.

I agree with commenter on your question that said "The asset pipeline isn't really meant to be compiling your assets each request in production. " -- making it not really possible to do exactly what you ask. So how about an alternative to accomplish what you're really trying to accomplish here, which is different asset resolution for different subdomains.

Put your sub-domain specific assets in sub-directories of your asset folders. Now, in the view/helpers, when you call asset_path or any other helpers that take a relative asset path, ask it for "#{subdomain}/name_of_asset" instead of just "name_of_asset". Now, because of the way the asset compiler works, it's possible this subdirectory method won't work, you may have to put the subdomain at the beginning of the actual filename instead."#{subdomain}_name_of_asset".

Not sure. And this still wouldn't give you a sort of 'default fall through' where some assets in some subdomains don't have subdomain-specific assets, they just 'fall through' to the default. Which would be nice.

It's possible a way can be figured out to do that too, not sure. But at any rate, following this approach of asking for a different asset at display-time using logic in view/helper.... is going to get you further than your original suggested approach, which probably isn't possible.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions