I have a project_todo model with a boolean attribute ‘status’. How would I display on the index page a loop that only lists project todos that have a status of false?
The regular loop that lists all project todos looks like this:
<% @project.project_todos.each do |todo|%>
<li data-id="<%= todo.id %>">
<%= todo.title %>
</li>
<% end %>
And I was playing around with a loop that only displays the todos IF the status is false by doing this:
<% @project.project_todos {status = "f"}.each do |todo|%>
<li data-id="<%= todo.id %>">
<%= todo.title %>
</li>
<% end %>
Am I anywhere close?
This will loop only on the project_todos that have a
status == false:OR, a better solution: you can do the following, and let ActiveRecord filter the
project_todositself:In extansion:
You can create a scope like following:
And use it like this: