Ruby Rails 个资产组织文件夹

Ruby on Rails asset organisation folders

我在 rails 上使用 ruby 5. app/assets、lib/assets 和 vendor/asset 有什么区别?

如果我编写自己的 js 脚本,它们应该包含在 app/assets 中吗?如果我使用 bootstrap 库,我应该把它放在哪里呢?

无论它们在哪个文件夹中,我都可以使用 javascript_include_tag 访问它们?示例:

javascript_include_tag "xmlhr"

asset pipeline guide所述:

  • 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. Keep in mind that third party code with references to other files also processed by the asset Pipeline (images, stylesheets, etc.), will need to be rewritten to use helpers like asset_path.

我,我只用app和vendor。我的东西自然而然地进入应用程序。第 3 方的东西(jquery 插件,bootstrap 主题等等)交给供应商。

app/assets

它应该包括您编写的所有资产,并且只与您的项目相关。

lib/assets

它应该包括所有由您创建但可以提取供另一个项目使用的资产。

vendor/assets

它应该包括来自第三方的所有资产 downloaded/purchased,例如 Bootstrap。