在SASS中访问Ruby变量(来自模型或控制器) [英] accessing Ruby variable(from model or controller) in SASS
问题描述
是否有一种方法可以在SASS中访问Ruby变量,或者我必须为其创建自定义函数?
Is there a way to access Ruby variables in SASS or do I have to make a custom function for it?
我想做的是为每个用户生成一个样式表,因此在控制器中,我会执行以下操作:
What I'm trying to do is to generate a stylesheet for each user so in the controller, I do something like:
def show
respond_to do |format|
format.css{render :partial => "styles"}
end
end
然后在视图名称_styles.haml中执行此操作:
then in the view name _styles.haml I do this:
:sass
#header
:background url(user.banner.url)
这有可能吗?
*显然不是: http://sass-lang.com/docs/yardoc/file.FAQ.html#q-ruby-code
除了我们所做的肮脏"代码修复之外,还有其他方法(然后将_styles部分转换为rhtml)
Is there a way other than this 'dirty' code fix we did(we converted _styles partial to rhtml then)
#header {
background: #efefef url(<%= @company.settings.banner.url %>);
}
有没有办法在haml中做到这一点?
is there a way for this in haml?
推荐答案
You could define a custom SassScript function (example) that inserts the value.
这篇关于在SASS中访问Ruby变量(来自模型或控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!