Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:08:05+00:00 2026-06-15T10:08:05+00:00

I have a project_todo model with a boolean attribute ‘status’. How would I display

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:08:06+00:00Added an answer on June 15, 2026 at 10:08 am

    This will loop only on the project_todos that have a status == false :

    <% @project.project_todos.select{|project_todos| project_todos.status == false}.each do |todo|%>
        <li data-id="<%= todo.id %>">
            <%= todo.title %>
        </li>
    <% end %>
    

    OR, a better solution: you can do the following, and let ActiveRecord filter the project_todos itself:

    <% @project.project_todos.where(status: false).each do |todo|%>
        <li data-id="<%= todo.id %>">
            <%= todo.title %>
        </li>
    <% end %>
    

    In extansion:

    You can create a scope like following:

    class ProjectTodo < ActiveRecord::Base
      #...
      scope :with_status, lambda{ |status| where(status: status) }
      #...
    end
    

    And use it like this:

    @project.project_todos.with_status(status: false) # Returns the project_todos with a status == false and belonging to the @project
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in a project that have a Person model. I display the
I have an Image Model that contains two booleans for IsMain and IsFeatured. I
I am trying to have a choicefield that only displays the users with the
I have a Django project, that has a Address model. This is used in
I have project model that has many tasks. Both project and tasks can have
I have a project that require me to do a auto complete search using
I have an ASP.NET MVC project that works fine on my local machine (no
I have two models, a Project and an Action: class Project(models.Model): name = models.CharField(Project
I have a project in which I have a database model class provided along
I know of at least two byte-code enhancer that modify the object model at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.