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

  • Home
  • SEARCH
  • 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 9228565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:22+00:00 2026-06-18T05:21:22+00:00

What I am trying to do is to come up with the model for

  • 0

What I am trying to do is to come up with the model for Project, where only one project could be active at a time. So I am thinking to create one table for projects and another one for status.

How can I make sure that only one project is active at a given time ? I looked into validates_uniqueness_of but I am little confused if thats the solution for me, because I do want to able to override the current status, despite the fact if one project is already enabled.

  • 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-18T05:21:23+00:00Added an answer on June 18, 2026 at 5:21 am

    Your Project should have something like an :active attribute. You can then add validation like this on your Project model

    validate :ensure_only_one_active_project
    
    def ensure_only_one_active_project
      active_project = Project.where(active: true).first
    
      errors.add(:active, "Another project is already active. Only one project can be active at a time") unless active_project.nil? || active_project.id == self.id
    end
    

    Now, if a Project already is active, and have another (currently inactive) Project @project, and try to do

    @project.active = true
    @project.valid? # this will return false
    

    @project.errors will contain a Hash with :active attribute having the above error since

    • 1 Project is already active
    • The active project is not the current Project we’re saving.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with a relational model and database implementation, but keep
I'm trying to create a Rails 3 model scope, which is, essentially: scope :published,
We’re trying to come up with something approaching a simple and straight-forward model for
I'm trying to come up with a standard way to create multiple forms for
I'm trying to create a build script for my current project, which includes an
I'm trying to come up with a model for managing Person and its Friends.
I have recently come across a problem trying to implement Model-View-Controller in Swing .
I’m trying to come up with a database/model design for product and related dynamic
im trying to come up with a design for a wrapper for use when
I'm trying to come up with an algorithm that will do the following: If

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.