Вопрос

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