我试图在编译期间将一些值从 Rails (3.2.12) 传递到 SASS (3.2.7) 文件。我尝试关注SASS 文档和其他一些关于 SO的答案。看起来它应该很简单,但我还没有设法克服这个错误:
undefined method `gsub' for nil:NilClass
(in /home/joegatt/Sites/joegatt.net/v3/joegattnet_v3/app/assets/stylesheets/application.css.sass)
我的设置是:
#/config/application.rb
if config.respond_to?(:sass)
require "#{config.root}/lib/sass.rb"
end
#/lib/sass.rb
module Sass::Script::Functions
def styling(string, opts = {} )
assert_type string, :String
Sass::Script::String.new( '#ff0000' )
end
declare :styling, :args => [:string]
end
#/assets/stylesheets/default.css.scss
background-color: styling('test')