我在 .haml 文件中有以下代码:
.row-fluid.page-header
%h2 My Programs
- if @program.students(:confirmed).first
- if !@program.students(:confirmed).first.fees_info['has_info']
.alert.alert-danger
We do not have your information on file!
如果我们没有为注册课程的学生设置“has_info”标志,则此代码将尝试打印警报消息。
我的问题是,编写上述两个 if 语句的更好方法是什么。
我尝试/想要在 if 语句中分配一个变量,但无法使其工作:例如,我尝试过:
- if first_record = @program.students(:confirmed).first
- if first_record.fees_info['has_info']
但这没有用。如何在这里声明一个可以在这些 if 语句中重用的变量?