Rails + Bootstrap;如果日期已过,则禁用

时间:2014-07-24 18:16:56

标签: ruby-on-rails twitter-bootstrap

我认为我有以下内容:

<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;用上面的代码。

2 个答案:

答案 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>