[Rails 3.2] How to extend a gem model

332 views
Skip to first unread message

Erwin

unread,
Jan 14, 2013, 3:00:53 AM1/14/13
to rubyonra...@googlegroups.com
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

Tommaso Visconti

unread,
Jan 14, 2013, 5:54:43 AM1/14/13
to rubyonra...@googlegroups.com
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

Romiras

unread,
Oct 12, 2015, 4:26:57 PM10/12/15
to Ruby on Rails: Talk
I'm trying to run migration to allow translation of tags with Globalize gem.

I've added config/initializers/acts_as_taggable_on.rb with following content:
ActsAsTaggableOn::Tag.class_eval do
  translates
:name
end

Running "bundler exec rake db:migrate" fails with error message:
undefined method `translates' for #<Class:0xba5eea10> (NoMethodError)

Is something I missing here?

Chirag Jain

unread,
Oct 13, 2015, 5:27:02 AM10/13/15
to Ruby on Rails: Talk
Try adding require n include statement
Reply all
Reply to author
Forward
0 new messages