我认为我有以下内容:
<td><%= check_box_tag 'checked_in', registration.id , registration.checked_in, :class => "check-in" %></td>
此特定复选框用于检查学生,并指出学生是否出现在课堂上。我希望在课程日期过后禁用该按钮。所以它看起来像:
<td><%= check_box_tag 'checked_in', registration.id , registration.checked_in, :class => "check-in",
if @orientation.class_date > Date.today then :disabled => "disabled" end %></td>
我收到语法错误&#34;期待keyword_end&#34;用上面的代码。
答案 0 :(得分:3)
删除if
语句并使用:
<td><%= check_box_tag 'checked_in', registration.id , registration.checked_in,
:class => "check-in", disabled: (@orientation.class_date > Date.today) %></td>
当@orientation.class_date > Date.today
时,复选框将处于disabled
状态,否则为enabled
。
答案 1 :(得分:1)
您也可以使用辅助方法
def check_for_disable(orientation)
true if orientation.class_date > Date.today
end
<td>
<%= check_box_tag 'checked_in', registration.id , registration.checked_in, :class => "check-in", :disabled => check_for_disable(@orientation)%>
</td>