So I've seen lots of discussion on SO about using erb in your CSS files. I can get ERB to process the CSS files by using the <%= %> syntax and adding .erb to the file, but what I really need is to access instance variables in the controller.
searches_controller.rb
def new
@search = Search.new
@school = School.find(params[:school])
end
What I would really like to do is:
searches.css.scss.erb
h1.logo {
color: <%= @school.primary_color %>;
}
but ERB will throw an error because @school is nil. Is there some way to require the controller to access those instance variables?
The only other way I can think to do it is to embed it as an data-attribute in the views and then use JS to change it on the front end. This strikes me as potentially better since the CSS file won't change and need to be resent every time, but it would also be a lot less elegant.