문제

I want to add custom methods to the Recurly::Account class by reopening it, and then use it in my controller.

something like this:

#reopen class
class Recurly::Account

  #my custom method
  def my_meth_1
  end

end

class MyController
  def index
    account = Recurly::Account.find( ... ) #gem method
    account.my_meth_1 #my custom method
  end
end

In which file should I reopen the Recurly::Account class and how should it be included in my controller?

도움이 되었습니까?

해결책

I think lib folder is a good place for this.

Simply create a file like this

# lib/recurly.rb

class Recurly::Account
  def my_meth_1
  end
end

how should it be included in my controller?

You will probably need to turn on autoloading from lib, see this topic how to do it Rails 3 autoload. After that, you can call it directly from controller.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top