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
的情况下解决这个问题?因为我需要在视图中将其显示为enum1
和enum3
答案 0 :(得分:0)
如http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
中所述当前边缘导轨提供enum_prefix
和enum_suffix
选项来处理不需要的枚举冲突。