2012-05-07 10 views
7

आउटपुट सीधे मेरे HAML टेम्पलेट के लिए इस सहायक के साथ क्या कर रहा है?haml_tag सीधे हैम टेम्पलेट

इस तरह
haml_tag outputs directly to the Haml template. 
Disregard its return value and use the - operator, 
or use capture_haml to get the value as a String. 

टेम्पलेट बुला रहा है display_event:

- @events.each do |event| 
    = display_event(event) 

अगर मैं नियमित रूप से मार्कअप उपयोग कर रहा था यह निम्नलिखित

%li.fooclass 
    %b Foo 
    %i Bar 
का विस्तार होगा

def display_event(event) 
    event = MultiJson.decode(event) 
    markup_class = get_markup_class(event) 
    haml_tag :li, :class => markup_class do 
     haml_tag :b, "Foo" 
     haml_tag :i, "Bar" 
    end 
    end 

यह त्रुटि है

उत्तर

10

सुराग युग में है आर संदेश:

Disregard its return value and use the - operator, 
or use capture_haml to get the value as a String. 
डॉक्स से haml_tag के लिए

:

haml_tag outputs directly to the buffer; its return value should not be used. If you need to get the results as a string, use #capture_haml .

इसे ठीक कर, या तो बदलने के लिए अपने Haml के लिए:

- @events.each do |event| 
    - display_event(event) 

(अर्थात capture_haml उपयोग करने के लिए = के बजाय - ऑपरेटर का उपयोग), या बदलने के विधि:

def display_event() 
    event = MultiJson.decode(event) 
    markup_class = get_markup_class(event) 
    capture_haml do 
    haml_tag :li, :class => markup_class do 
     haml_tag :b, "Foo" 
     haml_tag :i, "Bar" 
    end 
    end 
end 

इस विधि एक स्ट्रिंग, जिसे फिर आप अपने Haml में = साथ प्रदर्शित कर सकते हैं वापसी कर देगा।

नोट अगर आप दोनों वे एक दूसरे को रद्द हो जाएगा और आप कुछ भी नहीं दिखाया गया हो, केवल एक ही इन परिवर्तनों के बनाने की जरूरत है।

संबंधित मुद्दे