2个具有相同成员的枚举

时间:2015-05-17 03:19:49

标签: ruby-on-rails ruby ruby-on-rails-4 enums

class Class1 < ActiveRecord::Base

  enum enum1: [:val1, :val11, :val111]
  enum enum2: [:val22, :val22, :val222, :heavy]
  enum enum3: [:val1, :val11, val333] 

end

这会抛出错误

You tried to define an enum named "val1" on the model "Class1", but this will generate a instance method "val1?", which is already defined by another enum.

如何在不重命名val1的情况下解决这个问题?因为我需要在视图中将其显示为enum1enum3

1 个答案:

答案 0 :(得分:0)

http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html

中所述

当前边缘导轨提供enum_prefixenum_suffix选项来处理不需要的枚举冲突。

相关问题:https://github.com/rails/rails/issues/17511