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
On 12/5/05, Paul Chin <paulchin-0SqPFV7GnR3FK4RKhr3rmg@public.gmane.org> wrote:> 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 > > > endIt''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
Lachlan Laycock
2006-May-11 02:09 UTC
[Rails] Re: Possible Bug with intercept calls with alias_method
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) > > endHi, 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? -- Posted via http://www.ruby-forum.com/.