Forum: Ruby on Rails [Rails 3.2] How to extend a gem model

Posted by Kad Kerforn (kadoudal)
on 2013-01-14 09:02
(Received via mailing list)
I am using the gem  'acts-as-taggable-on' ( mbleigh) and I need to 
extend
the Tag model to  translate the tag name with Globalize
How can I add  "translates :name" into ActsAsTaggableOn::Tag ?  I can 
fork
the gem and modify my version, but is there any way to do it simply with
"extend ActiveSupport::Concern"  ?

currently :

module ActsAsTaggableOn
  class Tag < ::ActiveRecord::Base
    include ActsAsTaggableOn::Utils

    attr_accessible :name

needed :

module ActsAsTaggableOn
  class Tag < ::ActiveRecord::Base
    include ActsAsTaggableOn::Utils

    attr_accessible :name
translate :name
Posted by Tommaso Visconti (Guest)
on 2013-01-14 11:56
(Received via mailing list)
Erwin ha scritto:
> I am using the gem 'acts-as-taggable-on' ( mbleigh) and I need to extend
> the Tag model to translate the tag name with Globalize
> How can I add "translates :name" into ActsAsTaggableOn::Tag ? I can fork
> the gem and modify my version, but is there any way to do it simply with
> "extend ActiveSupport::Concern" ?

You can decorate the class:

ActsAsTaggableOn::Tag.class_eval do
   translate :name
end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.