我在HAML代码中需要这种结构:
- if @organisation.type == 'Company'
%p
%strong Number of Employees:
= @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
%p
%strong Number of Students
= @organisation.number_of_students
但我得到一个语法错误:得到了#34; elsif"没有先前的"如果" 我如何更新代码以解决错误?
答案 0 :(得分:6)
您的缩进看起来可能是问题
- if @organisation.type == 'Company'
%p
%strong Number of Employees:
= @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
%p
%strong Number of Students
= @organisation.number_of_students
如果注释不符合正确的缩进,则if / else语句将失败。
e.g。
- if @organisation.type == 'Company'
%p
%strong Number of Employees:
= @organisation.number_of_employees
-# Institutional case
- elsif @organisation.type == 'EducationalInstitution'
%p
%strong Number of Students
= @organisation.number_of_students
会失败。哪里
- if @organisation.type == 'Company'
%p
%strong Number of Employees:
= @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
-# Institutional case
%p
%strong Number of Students
= @organisation.number_of_students
是正确的。