我class
在 Haml 中定义了一个,我希望能够在这个类中使用 Haml 助手。例如:
- class Whatever
- def self.write
- haml_concat "something"
- Whatever.write
理想情况下,Whatever.write
会输出"something"
到模板,但它只是以undefined method 'haml_concat' for Haml::Engine::Whatever:Class
.
完整的堆栈跟踪:
haml_test.haml:5:in `write': undefined method `haml_concat' for Haml::Engine::Whatever:Class (NoMethodError)
from haml_test.haml:8:in `block in render'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/engine.rb:191:in `eval'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/engine.rb:191:in `render'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:281:in `process_result'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:41:in `parse'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:21:in `parse!'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/bin/haml:9:in `<top (required)>'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/bin/haml:19:in `load'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/bin/haml:19:in `<main>'
我怎样才能让它正常工作?我试过同时使用extend
and include
Haml::Helpers
,但它们也都失败了。有任何想法吗?