Access to Ruby variable (from model or controller) in SASS

Is there a way to access Ruby variables in SASS or do I need to make a custom function for it?

I am trying to create a stylesheet for each user, so in the controller I am doing 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 it even possible?

* Apparently this is not the case: http://sass-lang.com/docs/yardoc/file.FAQ.html#q-ruby-code

Is there any way besides this dirty correction of the code we made (we converted _styles, partial to rhtml, then)

 #header { background: #efefef url(<%= @company.settings.banner.url %>); } 

is there any way for this in haml?

+6
ruby ruby-on-rails sass haml
source share
1 answer

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

+5
source share

All Articles