1

I have the following in my view:

<td><%= check_box_tag 'checked_in', registration.id , registration.checked_in, :class => "check-in" %></td>

This particular check box is used to check students in, and indicates whether a student showed up for a class or not. I would like the button disabled after the class date has past. So it would look something like:

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

I get a syntax error "expecting keyword_end" with the above code.

Mark Locklear
  • 4,586
  • 1
  • 40
  • 73

2 Answers2

3

Remove the if statement and use this:

<td><%= check_box_tag 'checked_in', registration.id , registration.checked_in, 
:class => "check-in", disabled: (@orientation.class_date > Date.today) %></td>

When @orientation.class_date > Date.today, check box would be in disabled state otherwise enabled.

Kirti Thorat
  • 51,508
  • 9
  • 102
  • 107
1

You can also use a helper method

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>
Mandeep
  • 8,913
  • 2
  • 24
  • 36