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 7575559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:42:50+00:00 2026-05-30T16:42:50+00:00

In a Rails 3.2 app I have a model Project, which has many Tasks.

  • 0

In a Rails 3.2 app I have a model Project, which has many Tasks. Each Task has a :status field, which is an integer as follows

1=Normal
2=Urgent

In the Project show view, I want to display a text alert if any of the associated tasks are flagged as urgent.

If the status field was within the Project model, I would do something like this:

<% if Project.status == 2 %>
   <div class="alert">URGENT TASKS!</div>
<% end %>

How can I set up a similar if statement, that will cycle through all associated Tasks, and return true if at least one task is marked as urgent?

I’m not sure what terms I should be searching on for this sort of functionality. Or maybe I’m not looking at the problem the right way. I’d be grateful for any pointers in the right direction.

Thanks

  • 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-05-30T16:42:51+00:00Added an answer on May 30, 2026 at 4:42 pm

    This method in Project will do it:

    def urgent?
      tasks.detect{|t| t.status==2}
    end
    

    Then you can do, if you have @project set to the project you’re looking at:

    <% if @project.urgent? %>
      ...whatever ...
    <% end %>
    

    This next bit was added in answer to your comment. This method in Project will return the highest priority set (lowest number in your example) for any task in a particular project:

    def highest_priority
      tasks.map{|t| t.status}.min
    end
    

    You can then switch between them in your view:

    <% case @project.highest_priority
       when 1 %>
         ...priority 1 stuff...
    <% when 2 %>
         ...priority 2 stuff...
    <% when 3 %>
         ...and so on...
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a Rails 3.0 Todo app, I have a Tasks model with a Status
I have a model User and Listing in my rails app. User has many
I have a simple rails app with models project and phase. A project has
I have a notes model, which has a many-to-many relationship with the users model.
On my rails app I have a list of items (like a task list)
I have a Ruby on Rails project that has been untouched for a while,
I have a Project & Permissions Model. In my app I want to have
I have a model in my Rails app that uses the :class_name attribute for
In my Rails 2.3.2 app I have 2 models: class Post has_many :approved_comments, :class_name
I have a Rails app with some basic models. The website displays data retrieved

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.