简体   繁体   English

红宝石在轨道和资产

[英]ruby on rails and assets

i just started my first ruby app. 我刚刚启动了我的第一个ruby应用程序。

I copy the css and js files needed for my application to the assets folder and when i run the app all the css and js loaded to the page and i dont want that 我将应用程序所需的css和js文件复制到资产文件夹,当我运行该应用程序时,所有css和js都加载到页面中,我不希望那样

My view is simply 我的看法很简单

hello

my application.css is only comments 我的application.css仅是注释

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_self
 *= require_tree .
 */

Why all assets are loaded? 为什么要加载所有资产? Can i "disable" this? 我可以“禁用”此功能吗?

All i want is to define the files (css,js) needed in the view file with specific order and load js only needed for the specifif page 我要做的就是以特定顺序定义视图文件中所需的文件(css,js),并仅加载特定页面所需的js。

There are special comments. 有特别的评论。 Rails's preprocessor interprets it and inserts your files. Rails的预处理器会对其进行解释并插入文件。

 *= require_self
 *= require_tree .

Read The Asset Pipeline . 阅读资产管道 2.4 Manifest Files and Directives. 2.4清单文件和指令。

if you write *=require tree that means all the js on the javascript folder will be added, and same for the css. 如果您编写* = require树,这意味着将添加javascript文件夹上的所有js,并且对css也是如此。 so remove those lines. 因此删除这些行。 And at the same time you can use the assets manager to your application to manage your assets(make it page specific) to under stand assets management i will recommend you to check http://railscasts.com/episodes/279-understanding-the-asset-pipeline?view=asciicast and https://rails-assets.org/ 同时,您可以对应用程序使用资产管理器来管理您的资产(使其在特定页面上显示)以进行标准资产管理。我建议您检查http://railscasts.com/episodes/279-understanding-the -asset-pipeline?view = asciicasthttps://rails-assets.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM