每个动作的Rails Scss样式表 [英] Rails scss stylesheet per action

查看:104
本文介绍了每个动作的Rails Scss样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆