2009-07-28 8 views
11

मैं HAML के साथ शुरू कर रहा हूं और मेरी पहली फ़ाइल को परिवर्तित करने पर काम कर रहा हूं। के जाहिरा तौर पर सही चूक "- अंत":ईआरबी बनाम एचएएमएल रूपांतरण अगर एक शर्त है?

You don't need to use "- end" in Haml. Use indentation instead: 
- if foo? 
    %strong Foo! 
- else 
    Not foo. 

कैसे: एक ओर जहां तार्किक

- if current_user 
= link_to 'Edit Profile', edit_user_path(current_user.id) 
= link_to 'Logout', logout_path 
- else 
= link_to 'Register', new_user_path 
= link_to 'Login', login_path 
- end 

मुझे हो जाता है

app/views/layouts/application.html.haml:28: syntax error, unexpected kENSURE, expecting kEND 
app/views/layouts/application.html.haml:30: syntax error, unexpected $end, expecting kEND 

:

- if current_user 
= link_to 'Edit Profile', edit_user_path(current_user.id) 
= link_to 'Logout', logout_path 
- else 
= link_to 'Register', new_user_path 
= link_to 'Login', login_path 

मुझे हो जाता है क्या मुझे यह कंडीटी मिलती है एचएएमएल में काम कर रहे ओनल स्टेटमेंट?

+2

आप अपने सवाल में जवाब है .... त्रुटि संदेश आपको बताता है कि वास्तव में क्या करना है। – nitecoder

उत्तर

21

HAML इंडेंटेशन आधारित है, और पार्सर मुश्किल हो सकता है।

- if current_user 
    = link_to 'Edit Profile', edit_user_path(current_user.id) 
    = link_to 'Logout', logout_path 
- else 
    = link_to 'Register', new_user_path 
    = link_to 'Login', login_path 

साथ

- if current_user 
= link_to 'Edit Profile', edit_user_path(current_user.id) 
= link_to 'Logout', logout_path 
- else 
= link_to 'Register', new_user_path 
= link_to 'Login', login_path 

बदलें और इसे आजमाइए। ध्यान दें कि लिंक_to लाइनों पर इंडेंटेशन कैसे बदल गया।

+0

"असंगत इंडेंटेशन: इंडेंटेशन के लिए 5 रिक्त स्थान का उपयोग किया गया था, लेकिन शेष दस्तावेज़ को 2 रिक्त स्थानों का उपयोग करके इंडेंट किया गया था।" इसे पसंद नहीं आया। :( –

+1

आप कुछ बहुत अधिक जगहों को इंडेंट कर रहे हैं - या बहुत कम। क्या आप अपना पूरा टेम्प्लेट पोस्ट कर सकते हैं? –

+0

मैंने स्पेसिंग पर एक और नजर डाली और मुझे लगता है कि आप सही थे। मुझे लगता है कि मैंने इंडेंटिंग तय की है लेकिन अब मुझे यह मिल रहा है : /app/models/user_session.rb:5: सिंटैक्स त्रुटि, अप्रत्याशित '<' ^ /ऐप/मॉडल/user_session.rb: 8: सिंटैक्स त्रुटि, अप्रत्याशित TIDENTIFIER, $ ^ मुझे क्या याद आ रही है? –

3
- if current_user 
    = link_to 'Edit Profile', edit_user_path(current_user.id) 
    = link_to 'Logout', logout_path 
- else 
    = link_to 'Register', new_user_path 
    = link_to 'Login', login_path