rubygems - How/When/Where to Extend Gem Classes (via class_eval and Modules) in Rails 3? -


What is the recommended way to increase class behavior, through class_eval and module (inherited No) If I want to expand a class I was buried in a gem with a Rail 3 app?

An example is:

I want to add the ability to create permalinks for tags and categories (via ACTAtagGableOn and Acts Cebari Gems).

They have defined the tag and category models.

I basically want to do this:

  Category.class_eval do has_friendly_id: title end tag.class_eval do has_friendly_id: title end  

Although there may be other ways to add this functionality, it is typical for gem, what is the recommended way to add behavior to classes in a Rail 3 application like this?

I have some more gems I have made, I want to do this as a configuration model and a asset In an app / model / configuration I would like to be able to create RB model class, and it will work as I have done now class_eval .

Anyway, how should this work? I could not find anything covering any existing Rail 3 blog / docs / gist.

I do this, first add a file in the config / analyzer where you can add files to your extension You can:

  # config / initializers / extensions.rb "# railway root} /app/models/category.rb" "# {Rails.root} / app / models / tag .rb "is required  

Then you can reopen classes and add whatever you need:

  # app / model / category. RB class category has_friendly_id: title expiration  

The only downside is to restart the server to make any changes to these files, not sure if there is a better way Understand it.


Comments