这是具有枚举的模型:
class Admin::Dispatcher < ActiveRecord::Base
enum any_or_all: [:any_condition,:all_condition]
belongs_to :vendor_service,class_name: "VendorService"
belongs_to :admin_filter_group,class_name: "Admin::FilterGroup"
belongs_to :admin_filter_values,class_name: "Admin::FilterValues"
has_many :dispatcher_conditions,class_name: "Admin::DispatcherCondition",foreign_key: "admin_dispatcher_id"
has_many :dispatcher_actions,class_name: "Admin::DispatcherAction",foreign_key: "admin_dispatcher_id"
has_many :dispatcher_emails,class_name: "Admin::DispatcherEmail",foreign_key: "admin_dispatcher_id"
accepts_nested_attributes_for :dispatcher_conditions, allow_destroy: true
accepts_nested_attributes_for :dispatcher_actions, allow_destroy: true
attr_accessor :service,:vendor,:on,:condition_type,:condition,:filter,:filter_value,:any_or_all
end
请参考下面的屏幕截图,您可以看到我尝试更新模型,但没有更新:
答案 0 :(得分:0)
枚举有效,但any_or_all
未保存,因为Admin::Dispatcher
类的属性与attr_accessor
冲突。
您可以从any_or_all
列表中删除attr_accessor
,但它会有效。
这似乎是因为对象上的enum
方法defines a #{name}=
method,被attr_accessor
覆盖。