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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:47:10+00:00 2026-06-13T05:47:10+00:00

I am building a simple Ruby on Rails app for problem management. I have

  • 0

I am building a simple Ruby on Rails app for problem management. I have a problem model as follows:

class Problem < ActiveRecord::Base
  attr_accessible :active, :impact, :incident_number, :issue_description, :root_cause, :user_id, :problem_summary, :incident_priority, :timeline_enabled
  attr_accessor :enable_timeline

  validates :problem_summary, :length => { :in => 10..100 }

  belongs_to :user
  has_one :timeline
  has_many :actionitems

end

which has a has_many belongs_to association with the model for actionitems:

class Actionitem < ActiveRecord::Base
  attr_accessible :completion_date, :description, :initial_due_date, :notes, :problem_id, :revised_due_date, :status, :user_id

  belongs_to :problem
end

I would like to be able to update the problem record and save it with some set of limited validations (I still need to add those). However, I would like to have a “Complete problem investigation” button that would trigger a method on the problem controller to set the :active attribute on the problem record to false. I would like to be able to run a different, more complete set of validations on the problem record prior to performing this action and also to validate that all actionitems (if any) that were associated with this problem record are in :status “completed”.

The two questions that I have:

  1. How do I perform a specific set of validations only on a given action?
  2. How can I validate that related instances of Actionitem are in status “complete” prior to performing an action on Problem?

This task seems very complex to me. If you could please point me to what I need to utilize in order to be able to achieve this that would be greatly appreciated! (I read on validates :on => :save etc and accepts_nested_attributes_for but I am not sure how to put all of this together to achieve the behavior that I want).

Many thanks for all your help!

  • 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-13T05:47:11+00:00Added an answer on June 13, 2026 at 5:47 am

    try this

    validates_length_of :problem_summary, :in => 10..100, :if => :status_active?
    
    def status_active?
      self.active == true  
    end
    

    see in details – validations & validates_length_of

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a simple chat app with Rails. when a user types in a
Hi Im new to Ruby On Rails, but have experience building iPhone apps. So
I'm building a simple Ruby on Rails plugin and I'm considering using the Set
I am building a very simple game with Ruby on Rails. Two players are
I'm building an app in Ruby on Rails, and I'm including 3 of my
I'm using rails 2.3.5 and ruby 1.8.7. I'm building a simple TODO manager. Where
I'm building a simple app in ruby using the Sinatra framework. It's mainly get
I'm building simple phonebook. Thus a have created a class Person: public class Person
I'm building a referral program for my Ruby on Rails app, such that a
I am in the process of building a Ruby on Rails based SaaS app.

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.