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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:33:51+00:00 2026-05-19T11:33:51+00:00

I have a simple acts_as style module, that is included in ActiveRecord::Base. The purpose

  • 0

I have a simple acts_as style module, that is included in ActiveRecord::Base. The purpose of this module is to:

  1. add an has_one association to an ActiveRecord model

  2. add a missing method to instances, that will direct any missing methods to the associated instance.

Here is the example module:

module TestModule

  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods

    def test_me_out
      has_one :text_page
      send(:include, InstanceMethods)
    end

  end

  module InstanceMethods

    def method_missing(method, *args, &block)
      Rails.logger.debug "#{method}"
      #text_page.send(method, *args, &block)
      text_page
    end

  end
end

And the way I might use it in an AR model…

Class Page < ActiveRecord::Base
  test_me_out
end

The problem is, if the *method_missing* method in the module is run, it immediately causes a “stack level too deep” error inside the method_missing….

  app/lib/test_module.rb:24:in `method_missing'
  app/lib/test_module.rb:24:in `method_missing'
  app/lib/test_module.rb:24:in `method_missing'
  app/lib/test_module.rb:24:in `method_missing'
  app/lib/test_module.rb:24:in `method_missing'
  ...

The method that is missing is ‘id’ ?!? You’ll notice that I’ve commented out the example line of code that would send the missing method to the associated class – text_page.send(method, *args, &block) – since just calling the association – text_page – is enough to trigger the stack level too deep error.

Can anyone spot the error?

PS. Of course this is a boiled down example of the actual module and use case, however this illustrates the error, and fails wonderfully.


SOLUTION

Big thanks the Alex for the save. The ActiveRecord Id is generated dynamically using the method missing block. The following code works as it let the :id method missing to pass down into super:

def method_missing(method, *args, &block)
   if method != :id && text_page.respond_to?(method)
      text_page.send(method, *args, &block)
   else
      super
   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-19T11:33:51+00:00Added an answer on May 19, 2026 at 11:33 am

    Erik – If I remember correctly, AR uses method_missing to define attributes accessors and the like on the class, e.g. they are not hard coded. They are stored in instance variables, but the .id and .id= methods are defined on-the-fly. As a result, I’d recommend defining a way to match missing methods that you want referred to the associated interface.

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

Sidebar

Related Questions

I have this simple code that is working fine in every browser, but NOT
I have a simple rewrite rule that writes to an external domain using the
I have a simple class that contains a hashmap: @XmlRootElement() public class Customer {
I have a simple form that uploads an image to a database. Using a
I have simple test project which creates a frame and adds one JTextPane to
suppose I have simple C# code to print HELLO WORLD as shown in here
I have a simple SQL query (SQL Server 2005) where I'm selecting from a
I have a simple requirement (perhaps hypothetical): I want to store english word dictionary
I have a simple WCF service serving up notifications to and from an app.
I have a simple problem where I have 2 divs, 1 is relative positioned.

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.