Closed weepy closed 14 years ago
Jammit will happily load assets from wherever (relative paths are relative to Rails.root), but Rails won't directly serve files from outside the public directory. For this reason, it's recommended to either:
package_assets: always
, so that you're always dealing with the Jammit bundle.The first two options are best. Here's a similar ticket:
http://github.com/documentcloud/jammit/issues/closed#issue/5
Could Jammit not serve the files itself when in development mode ? It could load the assets via some kind of specific route.
We could do that, but I don't like the security hole. Rails only serves files from public because it's gives you a strong line between an open file, available for download, and your application, which must be kept secret. If Jammit just willy-nilly served up any file that matched a Directory glob, (usually a .js or a .css, but still) it would make it far too easy to expose your source by accident.
If you'd really like to keep them in a different folder, and symlinks aren't cutting it for you, then you can always add a controller and route to serve the files up directly for development.
It needn't be a security hole, because it could check that the file served matched a line in assets.yml (I.e. it's served anyway). Additionally it would only work in development mode, and revert to the normal packaged version in production.
I think it would be a great feature to have that would help Jamit address one of the rather broken features of Javascript development, namely reuse of source.
Hmm. Fair enough. I'd be glad to take a patch that works just like you just outlined, if you feel like contributing one.
We took a slightly different approach that allowed us to keep our plain JS files in app/javascripts while keeping them hidden in production: serving the files via rack middleware while in development mode. HTH someone (credit to @binary42 for the idea)
@hpoydar would you like to share the middleware you used?
Essentially we customized Rack::Static - http://github.com/rack/rack/blob/master/lib/rack/static.rb
@hpoydar I just wrote a quick bit of middleware that serves JS files in app/javascripts.
I'd be interested to see how you solved serving assets and whether you avoided including app in your development URI paths.
I'm not sure if this is possible already, but it didn't seem to work. What I'd like to do is load JS/CSS from other directories, e.g.
Is this possible ?