ruby-on-rails – 如何在Ruby on Rails中修补补丁?

让我们使用一个真实世界的例子.

我想修补一下WillPaginate :: LinkRenderer.to_html方法.

到目前为止,我尝试过:

>在文件夹中创建了一个文件:lib / monkeys / will_paginate_nohtml.rb
>在config / environments.rb中添加:在文件末尾需要’monkeys / will_paginate_nohtml’
>在该文件中,这是我的代码

Ë

module Monkeys::WillPaginateNohtml
  def to_html
    debugger
    super
  end
end

WillPaginate::LinkRenderer.send(:include,Monkeys::WillPaginateNohtml)

但不知何故,调试器无法通过.看起来修补失败了.

任何帮助将不胜感激,谢谢!

解决方法

那个怎么样:-) @ shingana的解决方案,@ kandadaboggu不会起作用,因为这里没有“超级”.您想要调用原始版本而不是超级版本.
module WillPaginate
  class LinkRenderer
    alias_method :to_html_original,:to_html
    def to_html
      debugger
      to_html_original
    end
  end
end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...