ruby-on-rails – Haml多行注释和if-elsif-else语句
发布时间:2020-12-17 02:54:45 所属栏目:百科 来源:网络整理
导读:我有以下代码. - if specializations.count = 0 .alert.alert-warning Warning message-# - elsif agency.offers_limit = agency.offers.count-# .alert.alert-warning-# Warning message- else = render 'form' 在这种情况下,我收到Got“else”,没有前面的
我有以下代码.
- if specializations.count <= 0 .alert.alert-warning Warning message -# - elsif agency.offers_limit >= agency.offers.count -# .alert.alert-warning -# Warning message - else = render 'form' 在这种情况下,我收到Got“else”,没有前面的“if”.我还能如何评论已经注释过的代码的一部分,以便 – 否则…正确处理? 如果我评论这样的代码: - if specializations.count <= 0 .alert.alert-warning Warning message -# - elsif agency.offers_limit >= agency.offers.count .alert.alert-warning Warning message - else = render 'form' 我没有错误,但是 – else …没有处理,也没有表单. 解决方法
不应在if – elsif – else语句中处理的代码应缩进.所以,如果在我的情况下我想跳过elsif语句,我的代码应如下所示:
- if specializations.count <= 0 .alert.alert-warning Warning message -# - elsif agency.offers_limit >= agency.offers.count -# .alert.alert-warning -# Warning message - else = render 'form' 或者像这样(为了保持正确的缩进): - if specializations.count <= 0 .alert.alert-warning Warning message -# - elsif agency.offers_limit >= agency.offers.count .alert.alert-warning Warning message - else = render 'form' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |