我尝试过了,认真地。有很多问题,但许多开发者都说“对我没用”,我是其中之一——很遗憾。
我正在研究最好的猴子补丁Rails gem的方法。我找到了几个,但决定使用这种方法。
我想要猴子补丁xeroizer gem,而不是invoice.rb model。
按照“这个方法”的链接,我认为这应该有效,但实际上并没有。 控制器:
“Xeroizer::Record::InvoiceModel”没有定义“invoice_url”方法。如何向Rails gem的类添加自定义方法?
我正在研究最好的猴子补丁Rails gem的方法。我找到了几个,但决定使用这种方法。
我想要猴子补丁xeroizer gem,而不是invoice.rb model。
# lib/xeroizer/invoice/invoice_url.rb
module Xeroizer
module Invoice
module InvoiceUrl
def invoice_url(id)
@application.http_get(@application.client, "#{url}/#{CGI.escape(id)}/OnlineInvoice")
end
end
end
end
按照“这个方法”的链接,我认为这应该有效,但实际上并没有。 控制器:
include Xeroizer::Invoice::InvoiceUrl
# Invoice.include Xeroizer::Invoice::InvoiceUrl
def some_method
# @xero is in a private method. It's here for short demonstration
@xero = Xeroizer::PrivateApplication.new("MY_CONSUMER_KEY", "MY_SECRET_KEY", "#{Rails.root}/privatekey.pem")
Rails.logger = @xero.Invoice.invoice_url("ad61ea97-b9e9-4a1e-b754-7c19e62f8cd7")
end
“Xeroizer::Record::InvoiceModel”没有定义“invoice_url”方法。如何向Rails gem的类添加自定义方法?
Xeroizer::PrivateApplication.class_eval ...
但从来没有成功过。也许我没有做对。 - Sylar