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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:21:23+00:00 2026-05-28T06:21:23+00:00

I want to make a after_update callback only execute when a certain configuration parameter

  • 0

I want to make a after_update callback only execute when a certain configuration parameter is true.
At first I had something like this:

after_update :do_something
...

def do_something
  return unless MyApp::Application.config.some_config
  actualy_do_something
end

But then I thought, why not make the callback assignment conditional?
Like this:

after_update :do_something if MyApp::Application.config.some_config

However I don’t fully understand what Im doing here. When would this change? Only on server restarts? How do I test this behavior ? I can’t just set the config, the model file won’t be read again.

Please advise.

  • 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-28T06:21:24+00:00Added an answer on May 28, 2026 at 6:21 am

    The standard way of achieving a conditional callback is to pass a symbol or proc to :if:

    before_create :generate_authentication_token, :if => :authentication_token_missing?
    after_destroy :deliver_thank_you_email, :if => lambda {|user| user.wants_email? }
    
    def authentication_token_missing?
      authentication_token.empty?
    end
    

    This format could also reference a global configuration setting on Rails.configuration

    after_update :refresh_cache, :if => :cache_available?
    
    def cache_available?
      Rails.configuration.custom_cache.present?
    end
    

    This would allow the behavior of the application to change without having to restart the server or remove a constant and reload the file.

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

Sidebar

Related Questions

This is a two part question, but I want to make sure the first
I want to make sure the user wants to have something pop up by
I want to make a Java game. At first the program asks for the
I know this may seem quite basic to geeks. But I want to make
I want to make my HTML and CSS like above to display a white
I want to make a button that starts my php script after I click
If I want to make a rule dynamic so i can use assert after
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog
I have style sheet with a class name changebackgroundcolor i want make change in

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.