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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:34:31+00:00 2026-06-12T07:34:31+00:00

on before_create, before_update, before_destroy methods, I would like to do an if: on multiple

  • 0

on before_create, before_update, before_destroy methods, I would like to do an if: on multiple constraints, such as

before_destroy :lock_quantity, if: [:processed, :quantity_changed]

so that if it’s been processed, the quantity cant change

(just in case:)

def lock_quantity
  errors.add :quantity, "You must revert the row before changing quantity"
end

so, is it possible to have multiple conditions for if:
?

  • 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-12T07:34:33+00:00Added an answer on June 12, 2026 at 7:34 am

    So, this should actually be like this…

    before_update :lock_quantity, if: [:processed, :quantity_changed?]
    

    Notice the question mark!

    (just in case:)

    def lock_quantity
      errors.add :quantity, "You must revert the row before changing quantity"
      false
    end
    

    pass false to stop saving

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

Sidebar

Related Questions

I'm a bit confused with the behavior of rpsec tests involving controller methods that
I found that stackoverflow old post that suggests model_entity.send(:before_create) but now it doesn't work.
I have following controller spec which passes. But I would like to replace create(:link)
I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
I've added a before_create filter to one of my Rails ActiveRecord models and inside
I have a model, for example : class Account < ActiveRecord::Base before_create :build_dependencies def
I want to a create dialog box like window before displaying the console window.
Let's say my controller looks like this: class MyController < ApplicationController before_filter :find_user,:only =>
I have made a simple Rails application that allows people to comment on posts.
I had hard time to figure out why I've been getting unknown action error

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.