开发者

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/in开发者_运维技巧itializers/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.


Try this:

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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜