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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:07:45+00:00 2026-06-13T14:07:45+00:00

I have a Rails 3.2 app that manages tasks. Here tasks are being assigned

  • 0

I have a Rails 3.2 app that manages tasks. Here tasks are being assigned to users. The task model has multiple user variables that are booleans. How would I add a validation to say that at least one user is set to true?

Original:

class Task < ActiveRecord::Base
  attr_accessible :title, :user1, :user2, :user3, :user4:
  validates :title, :presence => true
  validates :is_assigned


  def is_assigned
    if #AT_LEAST_ONE_USER_IS_TRUE
      errors.add("The task must be assigned to at least one user.")
    end
  end

end

Edited:

class Task < ActiveRecord::Base
  attr_accessible :title, :user1, :user2, user3, :user4

  validates :title, :presence => true
  validate :is_assigned

  def is_assigned
    unless @user1 || @user2 || @user3 || @user4
      errors.add(:user1, "The task must be assigned to at least one user.")
    end
  end

end

I’m getting closer I think but this does not work. The error seems to always appear.

Also it looks like errors.add requires another variable. How do I give it all users instead of just user1?

  • 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-13T14:07:46+00:00Added an answer on June 13, 2026 at 2:07 pm

    This ended up being my final solution:

    class Task < ActiveRecord::Base
      attr_accessible :title, :user1, :user2, user3, :user4
    
      validates :title, :presence => true
      validate :is_assigned
    
      def is_assigned
        unless user1 || user2 || user3 || user4
          errors[:base] << "The task must be assigned to at least one user."
        end
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that is using Devise, with a User model, no
I have a rails app that has asynchronous processing, and I'm having trouble getting
We have a Rails app that instantiates a SWF object 16 times (it has
I have a rails app that has a private component and a public component.
(Using Rails 3.1.3) I have an app that manages products. I import the products
I have a rails CMS app that manages content for a production web server
I have a rails app (rails3) that uses sessions for users to navigate upon
I have a rails app that has picked up a bit of traction, but
I'm working on a Rails app where Users can have multiple roles, e.g. Manager,
I have a Rails app that is served by Apache and Passenger, using only

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.