Sta*_*erd 2 haml ruby-on-rails
我需要在我的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
Run Code Online (Sandbox Code Playgroud)
但我得到一个语法错误:得到"elsif"没有前面的"如果"我如何更新我的代码来解决错误?
您的缩进看起来可能是问题
- 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
Run Code Online (Sandbox Code Playgroud)
如果注释不符合正确的缩进,则if/else语句将失败.
例如
- 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
Run Code Online (Sandbox Code Playgroud)
将失败.哪里
- 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
Run Code Online (Sandbox Code Playgroud)
会是对的.