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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:35:55+00:00 2026-05-13T12:35:55+00:00

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment,

  • 0

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment, I would like to have a separate file which modifies Message by adding a callback. So, instead of doing:

# app/models/message.rb
class Message < ActiveRecord::Base
  before_save :foo
  def foo
     puts 'foo!'
  end
end

I would like to be able to do:

# app/models/message.rb
class Message < ActiveRecord::Base
end

# config/initializers/fixes.rb
Message
class Message
  before_save :foo
  def foo
     puts 'foo!'
  end
end

Problem is, it works when I start the script/console, but when I start it using script/server it usually doesn’t. That is the worst part, it isn’t that it never works. Sometimes I start the server and it works, sometimes it doesn’t, and that is without making any changes to the source.

I am restarting the server itself as (as far as I know) the initializers are run only once and don’t get reloaded if modified.

I know the ‘sometimes’ works is very vague, but I have spent hours here without any luck. Perhaps someone has had a similar issue, or can come up with a different idea to add the callback.

  • 1 1 Answer
  • 2 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-13T12:35:55+00:00Added an answer on May 13, 2026 at 12:35 pm

    Why not use observers? (http://api.rubyonrails.org/classes/ActiveRecord/Observer.html)

    For example, you’d do something like this:

    class MessageObserver < ActiveRecord::Observer
      def before_save(message)
        puts 'you win at ruby!'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Product model: class Product < ActiveRecord::Base belongs_to :subcategory define_index do #
I have a Model class, which contains Lists of Message s and Signal s.
I have a web service , i add some extra class which have message
I have a message handler, which consumes from a JMS queue and that sends
I have got an Entity model which contains a collection of Message objects which
I have an Address Model which has a ForeignKey to a Contact Model: class
Hay, I'm using MPTT to create some tree-like data from a model which contains
I have a users_manager engine which has a User model class. In an other
I have a strong typed view model and a MetaData partial class which has
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to

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.