开发者

accessing Ruby variable(from model or controller) in SASS

开发者 https://www.devze.com 2023-01-02 07:20 出处:网络
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 l

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.co开发者_运维百科m/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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消