I have a setup where I have an engine (non-namespaced) for each subdomain. This works great because each subdomain is able to specify their own custom routes, controllers, views, and models. But I haven’t been able to figure out how to get assets to do what I want them to. Ideally javascript and stylesheets are only loaded for a particular subdomain if that subdomain is visited. I don’t want one stylesheet definition overwriting another in a different community.
Furthermore, I’d like images to be accessible as normal when using image_tag.
I’ve figured out a solution. The JS, CSS, and images should all be stored in the default location of the engine, e.g.
app/assets/javascripts/<subdomain>/application.js. Then, in the main app’sapplication.html.erbJS and CSS should be included like so:As for images, as long as they’re in
app/assets/images/<subdomain>/of the engine, they’ll show up in public as/assets/images/<subdomain>/my_image.png. Again, I’m using Rails 3.1; I’m not sure how this behavior is for other versions of Rails, including 3.0.