每个动作的Rails Scss样式表 [英] Rails scss stylesheet per action
问题描述
如何在Rails中为每个动作渲染样式表?
How can I render a stylesheet per action in rails?
由于我的应用程序不是标准的CRUD应用程序,因此我的控制器最终会获得一些需要非常不同的CSS的自定义路由.
Since my app is not the standart CRUD app, my controllers end up with a few custom routes which require very different CSS's.
所以,我想知道,有什么方法可以按动作加载css,但仍然可以利用资产管道吗?
So, I'm wondering, is there any way to load the css on a per action basis but still take advantage of the asset pipeline?
谢谢
推荐答案
您可以使用控制器特定的资产.只需从application.css中删除*= require_tree .
.并通过<%= stylesheet_link_tag "style.css" %>
在其视图中包括样式表特定于动作的样式表,但是您必须通过Rails.application.config.assets.precompile = ["style.css"]
告诉rails对其进行编译.您可以在此处了解更多信息.这样,我想我们不是以默认方式使用Rails资产管道.
You can use controller specific assets. Just remove the *= require_tree .
from application.css. And include the stylesheet the action specific stylesheet in its view by <%= stylesheet_link_tag "style.css" %>
but you have to tell rails to compile them by Rails.application.config.assets.precompile = ["style.css"]
. You can read more about it here. This way I guess we are using rails assets pipelines just not in default way.
这篇关于每个动作的Rails Scss样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!