accessing Ruby variable(from model or controller) in SASS

元气小坏坏 提交于 2019-12-06 02:03:47

问题


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

then in the view name _styles.haml I do this:

:sass
  #header
    :background url(user.banner.url)

is this possible at all?

*Apparently it isn't: http://sass-lang.com/docs/yardoc/file.FAQ.html#q-ruby-code

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 %>);
}

is there a way for this in haml?


回答1:


You could define a custom SassScript function (example) that inserts the value.



来源:https://stackoverflow.com/questions/2964501/accessing-ruby-variablefrom-model-or-controller-in-sass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!