In my application a user can say they have completed a piece of homework.

A field "completed\_on" is populated with the date the homework was completed. If not completed the field is blank.

I would like to show a tick if the homework is completed or an x if the homework is not completed.

The column "completed\_on" is located in a table called homework\_students.

```
class Homework < ActiveRecord::Base
    has_many :homework_students, :class_name => 'HomeworkStudent'

class HomeworkStudent < ActiveRecord::Base
    belongs_to :homework, :class_name => 'Homework'

```

I have tried the following which does not work for me:

In my model:

```
def getCompletion
      homework_students.where("completed_on is not null")
end

```

View:

```
<% if homework.getCompletion %><%= image_tag "fi-check.svg", class: "homework_student_complete" %><% else %><%= image_tag "fi-x.svg", class: "homework_student_complete" %><% end %>

```

I also tried this:

Model

```
def completed?
    !homework.homework_student.completed_on.blank?
end

```

View

```
<% if homework.completed? %>
<%= image_tag "fi-check.svg", class: "homework_student_complete" %><% else %><%= image_tag "fi-x.svg", class: "homework_student_complete" %><% end %>

```

Appreciate any guidance.

UPDATE

This works:

```
def completed?
      homework_students.where("completed_on is not null").length == 0 
    end

<% @homeworks.each do |homework| %>
...
 <td height="1" class="text-center"><% if homework.completed? %>
  <%= image_tag "fi-check.svg", class: "homework_student_complete" %>
<% else %>
  <%= image_tag "fi-x.svg", class: "homework_student_complete" %>
<% end %></td>
...
<% end %>

```