Nico
Nico

Reputation: 931

Rails 3.1: Model Constant in initializer causes warning

I have monkey patched the Tag class of the ActsAsTaggableOn plugin in an an initializer. All works fine, however I get a warning for a constant I added to Tag:

config/initializers/acts_as_taggable_on_extensions.rb:

 class Tag < ActiveRecord::Base

   ... some stuff ...

   TAG_TYPES = [:a, :b, :c]

   ... some more stuff ....

 end

The warning is: config/initializers/acts_as_taggable_on_extensions.rb:136: warning: already initialized constant TAG_TYPES

How can I get rid of this warning?

I'm on ruby 1.9.2, Rails 3.1 rc4.

Upvotes: 1

Views: 591

Answers (2)

Andrea Salicetti
Andrea Salicetti

Reputation: 2483

Try this:

TAG_TYPES ||= [:a, :b, :c]

Upvotes: 2

Aurril
Aurril

Reputation: 2469

You can add your own Tag Types by adding them to the TAG_TYPES array.

TAG_TYPES << :a << :b << :c
TAG_TYPES.uniq!

Upvotes: 0

Related Questions