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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:07:50+00:00 2026-05-28T03:07:50+00:00

I have an object with multiple validations. gist of the Approval model: https://gist.github.com/1579150 (side

  • 0

I have an object with multiple validations.

gist of the Approval model: https://gist.github.com/1579150 (side note, I know the Email Domain Validor doesn’t work…)

The point is, if these validations fail, I want the object to save, but then set a value on approval.issue = true. Approval.issue is a boolean field that defaults to false, but then if the object fails validations I want the system admin to be able to see it and then handle it appropriately.

To make it more idiot proof, it would be nice to have some validations that can force the user to make changes, but then some would be exempt and would simply trigger the .issue field to true.

For instance, if the email is of the right domain but the email doesn’t exist in the system, it would save it but then set issue => true. I could then set up a simple view for Approvals where :issue => :true. then the admin could modify or delete bad Approvals.

Ideas?

Code from gist:

class Approval < ActiveRecord::Base
  class ApproverEmailValidator < ActiveModel::EachValidator

     def validate_each(approval, attribute, value)
       approval.errors[attribute] << "must be a valid e-mail address in our system" unless is_valid_email?(value)
     end

protected
     def is_valid_email?(address)
       User.find_by_email(address)
     end

end # End Approver Validator

class EmailDomainValidator < ActiveModel::EachValidator
   def email_domain_is?(domain)
     unless /ravennainteractive.com$/ =~ email(domain)
         errors.add(:email, "You must Use an Eddie Bauer email address")
     end
   end
end #End Email Domain Validator

  belongs_to :recommendation
  attr_accessible :approval, :email, :user_id
  validates :email, :email_domain
  validates :next_approver_email, :approver_email => { :if => :recently_approved? }
  before_save :create_next_approval
  after_create :approval_notification

  attr_accessor :next_approver_email

  def recently_approved?
      self.approved_changed? && self.approved?
    end

  def create_next_approval
      next_approval = self.recommendation.approvals.build(:email => self.next_approver_email, :user_id  => User.find_by_email(next_approver_email))
      next_approval.save  if next_approver_email.present? && recently_approved? 
  end 

  def email_domain_is?
    unless /ravennainteractive.com$/ =~ email
        errors.add(:email, "You must Use an Eddie Bauer email address")
    end
  end


private
  def approval_notification
    ApprovalMailer.needs_approval(self).deliver
  end

end
  • 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-28T03:07:50+00:00Added an answer on May 28, 2026 at 3:07 am

    You can implement observer for Approval that will analyze you objects before saving and set issue to “true”, if there is some suspicious input.

    UPDATE: Here is short guide how to implement observer:

    1. rails generate observer – after this step you`ll see _observer.rb file.

    2. Implement needed methods. Here is simple example extracted from one of my projects (It seems like you should use “before_save” method):

      class HomeworkObserver < ActiveRecord::Observer
          def after_create(homework)
              TeacherMailer.send_later(:student_submitted_homework, homework)
           end
      
           def after_save(homework)
               if (homework.checked)
                   StudentMailer.send_later(:teacher_checked_homework, homework)
               end
           end
      end
      

    Also you need to enable observer by adding it to your config/application.rb, e.g:

        config.active_record.observers = :homework_observer
    

    Official docs: http://api.rubyonrails.org/classes/ActiveRecord/Observer.html

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

Sidebar

Related Questions

I have object A which contains multiple instances of object B, which in turn
I have a string object with multiple characters and even special characters I am
I have an object (Client * client) which starts multiple threads to handle various
I have been attempting to have a object that I can use across multiple
I have a List object being accessed by multiple threads. There is mostly one
Is it possible to have multiple view of the same display object? (e.g. same-computer
I'd like to have multiple versions of an object with different access modifiers on
I have an object that serves multiple requests (threads) ... think of SqlConnection object
For a current MVC3 project I have a model that has multiple pages for
I have defined a custom object with multiple fields. For example say I have

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.