如何设置一个变量从辅助方法包含在SASS SCSS样式表? [英] How to set a variable from a helper method for inclusion in a SASS SCSS stylesheet?
问题描述
我有一个帮助方法来检索我需要进入SASS scss样式表的字符串。如果我在视图中调用该方法工作正常,但似乎sass是想要一个变量。似乎如果我试图在控制器中设置一个var,认为这是最初的正确方法,我不能看到var任何地方。
I have a helper method that retrieves a string that I need to get into a SASS scss stylesheet. If I call the method in the view it works fine, however it seems that sass is wanting a variable. It seems as though if I attempt to set a var in the controller, thinking that this would be the correct approach initially, I'm not able to see the var anywhere.
如果没有,
I initially thought you could simply call a helper method from SASS, but apparently that's not the case? If not,
可能你可以提供一个例子,在一个最初来自辅助方法的sass scss样式表中正确地获取变量。
推荐答案
将SASS文件重命名为 foobar.css.scss.erb
。然后通过将此行放在顶部,包含您需要的包含帮助方法的帮助程序模块:
Rename your SASS file to foobar.css.scss.erb
. Then include the helper module you need that contains the helper method by placing this line at the top:
<% environment.context_class.instance_eval { include MyHelper } %>
然后您可以使用帮助方法与erb
Then you can use the helper method with erb
.foo {
color: <%= cool_color %>
}
这篇关于如何设置一个变量从辅助方法包含在SASS SCSS样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!