ruby on rails - undefined method `output_buffer=' for content_tag with block -


में lib / my_lib.rb

  वर्ग MyLib में ActionView :: मददकर्ता :: टैगहेल्पर Def foo content_tag: div do "hello" end end end   

देता है

  की आवश्यकता 'lib / my_lib'; MyLib.new.foo NoMethodError: अपरिभाषित विधि # output_buffer = 'के लिए & lt; MyLib: 0x7f3209aaa450 & gt; से /var/lib/gems/1.8/gems/actionpack-3.0.5/lib/action_view/helpers/capture_helper.rb:175:in_with_output_buffer '/var/lib/gems/1.8/gems/actionpack-3.0 से। 5 / lib / action_view / सहायकों / कैप्शन_हेल्पर.आरबी: 40: `/ कैपिटल में /var/lib/gems/1.8/gems/actionpack-3.0.5/lib/action_view/helpers/tag_helper.rb:77:in` Content_tag './lib/my_lib.rb:6 से' foo 'से (irb): 1    

क्या कोई विशेष कारण है कि आप इस तर्क को किसी दृश्य के अंदर नहीं डाल सकते?

content_tag दृश्य वातावरण के लिए बनाया गया था, और इसे नियंत्रक या अन्य के भीतर से कॉल करने का इरादा नहीं था पुस्तकालय। आपको अपने मैलीबब वर्ग को एक दृश्य के रूप में स्थापित करने की आवश्यकता होगी।

जब मैं सुझाता हूं कि आप फिर से सोचते हैं, और अपने कोड और डिज़ाइन की गंध करते हैं जिससे आपको इसकी जरूरत होती है, तो आप कर सकते हैं ActionView :: Base से उप-क्लासिंग द्वारा आप क्या चाहते हैं पूरा करें <पूर्व> वर्ग MyLib & lt; ActionView :: बेस में ActionView :: हेल्पर्स :: टैगहेल्पर def foo content_tag: div "हैलो" एंड एंड एंड

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -