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 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

It seems simple, in my model I have: class CustomerAccount < ActiveRecord::Base acts_as_url :name
I have a very simple ASP.Net page that acts as a front end for
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple VB.NET form that acts as an interface to a control
I have a simple image inside an HTML form that acts as a button.
This should be simple but I cannot figure it out. I have this very
I have created a very simple Entity Framework 4.0 model using VS2010 Professional. Ignore
I have a program that displays information(simple text, but not in a txt box,
I know this has been asked many times before... I have a simple ('#Div').load(file.php?id='+id+'&page='+page)
I am aware that I can share simple Objects using LocalConnection, but this does

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.