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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:00:52+00:00 2026-05-27T18:00:52+00:00

I have a bunch of models which currently extend ActiveRecord::Base. For all these models,

  • 0

I have a bunch of models which currently extend ActiveRecord::Base.

For all these models, I want to extend the save! method with some additional functionality. For example,

def save!
  begin
    super
  rescue 
    # additional exception handling logic
  end
end

What is the ideal way to do this in an OOP fashion?

I tried subclassing ActiveRecord (MyActiveRecord) and used the above code in the subclass. Then I used the subclass as the parent class for all my models. But then, ActiveRecord tries to find the table myapp_test.my_active_records.

Is there a more elegant way using modules which achieves the same thing?

  • 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-27T18:00:53+00:00Added an answer on May 27, 2026 at 6:00 pm

    If you mark a class as abstract:

    class Foo < ActiveRecord::Base
      self.abstract_class = true
    end
    

    then you can subclass from it and rails won’t go looking for a foos table.

    In this particular case I wouldn’t overwrite save though – there’s already a set of callbacks (around_save, around_update etc) that probably make more sense.

    Even if you were to do it by overwriting the save method, it might make more sense to do it by putting your overwritten save method in a module and including that module in the classes that require it.

    module MySave
      def save!
        super
      rescue
      ...
      end
    end
    
    class MyClass < AR::Base
      include MySave
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process which iterates through a bunch of ActiveRecord models, does some
I have a bunch of classes I want to rename. Some of them have
I have a Rails application with several models-views-controllers which have some similar characteristics, for
I have a backbone collection which has a bunch of models with date attributes
We have bunch of Domain Entities which should be rendered to an html format,
week DKK id=radio2 value=75 /> I have bunch of these div entry generated by
I have a Zend_Framework application, which has a whole bunch of model classes. I
I have a database repository with a bunch of access functions. I now want
I currently have an entity model with a bunch of deleted items, the state
I'm creating a bunch of migrations, some of which are standard create table or

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.