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
  • 5,044
  • 1
  • 51
  • 81
  • 1
    Use [ternary operator](http://stackoverflow.com/questions/4252936/how-do-i-use-the-conditional-operator-in-ruby) – Roman Kiselenko Jul 24 '14 at 18:28
  • Yes, this works: <%= check_box_tag 'checked_in', registration.id , registration.checked_in, :disabled => @orientation.class_date < Date.today ? true : false, :class => "check-in" %> – Mark Locklear Jul 24 '14 at 18:36

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
  • 52,578
  • 9
  • 101
  • 108
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
  • 9,093
  • 2
  • 26
  • 36