I am new to ruby on rails
and whenever i create and access
a controller
i can see it loads a new css & js
file with name as the name of the controller...
我是ruby on rails的新手,每当我创建并访问控制器时,我都可以看到它加载一个新的css&js文件,其名称为控制器的名称...
How can i make it load only 1 css and js
file called style.css
and site.js
for example?
我怎么能只加载1个名为style.css和site.js的css和js文件呢?
what is the purpose of having multiple js & css
files whenever i access a contrller?
每当我访问一个控制器时,有多个js和css文件的目的是什么?
if i go to application.html.erb
and change
如果我去application.html.erb并改变
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
to
<%= stylesheet_link_tag("application") %>
<%= javascript_include_tag("application") %>
it doesnt seem to help
它似乎没有帮助
3 个解决方案
#1
1
The code:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
will include all .css
and .js
files available in assets/javascripts/
and assets/stylesheets/
. So, if you want to include only the style.css
and site.js
just remove everything else.
将包括assets / javascripts /和assets / stylesheets /中提供的所有.css和.js文件。因此,如果您只想包含style.css和site.js,请删除其他所有内容。
Your assets/javascripts/
should have only the application.js
and site.js
.
您的assets / javascripts /应该只包含application.js和site.js.
And your assets/stylesheets/
should have the application.css
and style.css
.
你的资产/样式表/应该有application.css和style.css。
EDIT
`application.js
and application.css
are part of the asset pipeline.
`application.js和application.css是资产管道的一部分。
You can disable it if you want by adding this line in your application.rb
如果需要,可以在application.rb中添加此行来禁用它
config.assets.enabled = false
You can also change the application.html.erb
to include only your style.css
and site.js
:
您还可以将application.html.erb更改为仅包含style.css和site.js:
<%= stylesheet_link_tag "style", :media => "all" %>
<%= javascript_include_tag "site" %>
I hope it helps...
我希望它有帮助......
#2
2
I dont know which Rails version you are using, but assuming it is the recent one, then Rails are using Assets Pipeline, to merge multiple files and serve all css / javascript files compressed / merged.
我不知道你正在使用哪个Rails版本,但假设它是最近的版本,那么Rails正在使用Assets Pipeline,合并多个文件并提供压缩/合并的所有css / javascript文件。
You can learn more about it at http://guides.rubyonrails.org/asset_pipeline.html
您可以在http://guides.rubyonrails.org/asset_pipeline.html上了解有关它的更多信息
Basically what you do is, you reference one file 'application' (css or js) and inside this file, you customize which files it should include.
基本上你所做的是,你引用一个文件'application'(css或js),在这个文件中,你自定义它应该包含哪些文件。
#3
0
Try using :cache => 'cache-display'
尝试使用:cache =>'cache-display'
<%= stylesheet_link_tag :all, :cache => 'cache/display' %>
<%= javascript_include_tag :all, :cache => 'cache/display' %>
#1
1
The code:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
will include all .css
and .js
files available in assets/javascripts/
and assets/stylesheets/
. So, if you want to include only the style.css
and site.js
just remove everything else.
将包括assets / javascripts /和assets / stylesheets /中提供的所有.css和.js文件。因此,如果您只想包含style.css和site.js,请删除其他所有内容。
Your assets/javascripts/
should have only the application.js
and site.js
.
您的assets / javascripts /应该只包含application.js和site.js.
And your assets/stylesheets/
should have the application.css
and style.css
.
你的资产/样式表/应该有application.css和style.css。
EDIT
`application.js
and application.css
are part of the asset pipeline.
`application.js和application.css是资产管道的一部分。
You can disable it if you want by adding this line in your application.rb
如果需要,可以在application.rb中添加此行来禁用它
config.assets.enabled = false
You can also change the application.html.erb
to include only your style.css
and site.js
:
您还可以将application.html.erb更改为仅包含style.css和site.js:
<%= stylesheet_link_tag "style", :media => "all" %>
<%= javascript_include_tag "site" %>
I hope it helps...
我希望它有帮助......
#2
2
I dont know which Rails version you are using, but assuming it is the recent one, then Rails are using Assets Pipeline, to merge multiple files and serve all css / javascript files compressed / merged.
我不知道你正在使用哪个Rails版本,但假设它是最近的版本,那么Rails正在使用Assets Pipeline,合并多个文件并提供压缩/合并的所有css / javascript文件。
You can learn more about it at http://guides.rubyonrails.org/asset_pipeline.html
您可以在http://guides.rubyonrails.org/asset_pipeline.html上了解有关它的更多信息
Basically what you do is, you reference one file 'application' (css or js) and inside this file, you customize which files it should include.
基本上你所做的是,你引用一个文件'application'(css或js),在这个文件中,你自定义它应该包含哪些文件。
#3
0
Try using :cache => 'cache-display'
尝试使用:cache =>'cache-display'
<%= stylesheet_link_tag :all, :cache => 'cache/display' %>
<%= javascript_include_tag :all, :cache => 'cache/display' %>