gpt4 book ai didi

ruby-on-rails - HAML:得到 "elsif",前面没有 "if"

转载 作者:行者123 更新时间:2023-12-01 19:34:08 25 4
gpt4 key购买 nike

我的 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

但是我得到一个语法错误:得到了前面没有“if”的“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

额外的缩进怪癖

如果评论不符合正确的缩进,则 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

会失败。在哪里

- 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

意志是正确的。

关于ruby-on-rails - HAML:得到 "elsif",前面没有 "if",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32865581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com