# Possible Bug with intercept calls with alias\_method

**URL:** <https://www.ruby-forum.com/t/possible-bug-with-intercept-calls-with-alias-method/49482>\
**Category:** Rails\
**Created:** [December 5, 2005, 7:26am UTC](https://www.ruby-forum.com/t/possible-bug-with-intercept-calls-with-alias-method/49482 "2005-12-05T07:26:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulchin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8797f3/32.png) [@paulchin](https://www.ruby-forum.com/u/paulchin)\
**Post date:** [December 5, 2005, 7:26am UTC](https://www.ruby-forum.com/t/possible-bug-with-intercept-calls-with-alias-method/49482/1 "2005-12-05T07:26:29Z")

</div>

Hi all I’m trying user alias\_method to overload the link\_to method, It  
works the first time, but when I reload the page, it will have an error  
“stack level too deep”.

I’m using rails 0.14.3 ruby 1.8.2 Webrick in winxp, I suspect it is a  
bug.

this is my helper’s code

module UsersHelper  
include ActionView::Helpers::UrlHelper

alias\_method :link\_to\_original, :link\_to

def link\_to(name, options = {}, html\_options =  
nil,\*parameters\_for\_method\_reference)  
if permission?  
link\_to\_original( name,  
options,html\_options,\*parameters\_for\_method\_reference )  
end  
end

end

---

<div class="post-metadata">

**Author:** ![paulchin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8797f3/32.png) [@paulchin](https://www.ruby-forum.com/u/paulchin)\
**Post date:** [December 5, 2005, 7:51am UTC](https://www.ruby-forum.com/t/possible-bug-with-intercept-calls-with-alias-method/49482/2 "2005-12-05T07:51:16Z")

</div>

On 12/5/05, Paul C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end

It’s probably running that on every request. On the second request it  
maps your new link\_to to link\_to\_original. Try surrounding it in  
this:

unless respond\_to?(:link\_to\_original)

end

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![paulchin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8797f3/32.png) [@paulchin](https://www.ruby-forum.com/u/paulchin)\
**Post date:** [May 11, 2006, 4:09am UTC](https://www.ruby-forum.com/t/possible-bug-with-intercept-calls-with-alias-method/49482/3 "2006-05-11T04:09:10Z")

</div>

technoweenie wrote:

> It’s probably running that on every request. On the second request it  
> maps your new link\_to to link\_to\_original. Try surrounding it in  
> this:
> 
> unless respond\_to?(:link\_to\_original)
> 
> end

Hi, I am trying to do the same thing and unfortunately the respond\_to?  
approach doesn’t have any affect.

Any ideas on how to overload the link\_to function?
