Rails Rails 3.1 的 assets 该如何安排?

bryanwong · February 16, 2012 · Last by jinleileiking replied at February 23, 2012 · 4066 hits

js, css 和 image 可以放在 app/assets 和 vendor/assets 两个目录, 有什么 best practice 来安排吗?看了 ruby-china 的代码,没总结出规律来。

我的做法是:项目自己写的放 app/assets,三方的放 vendor/assets

自己寫的關於 util 類的,我放 lib/assets/ 第三方的比如說是 jquery.ui.* 的我放 vendor/assets/

至於是比如說 project 內獨有,特別是 controller specific, 或者是 feature specific 的,我才放 app/assets

我的做法是 需要 precompile,外部访问的的东西放在 app/assets 共用的放在 lib/assets 第三方的放在 lib/assets

这样在设置 precompile 的时候只要设置成 app/assets 里面的 js 和 css 就好了

verdor 在 rails4 发布时,是不是就去掉了?现在来说第三方的是不是放 lib/assets 下比较好?

放在 vendor/assets/ 或者 lib/assets 下的东西 js,css 应该如何加载到页面?

rails guide 有!

2.1 Asset Organization Pipeline assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets.

app/assets is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets.

lib/assets is for your own libraries’ code that doesn’t really fit into the scope of the application or those libraries which are shared across applications.

vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.

You need to Sign in before reply, if you don't have an account, please Sign up first.