Rails 4.1枚举值未保存

时间:2014-06-12 14:16:19

标签: ruby-on-rails enums

这是具有枚举的模型:

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

请参考下面的屏幕截图,您可以看到我尝试更新模型,但没有更新:

enter image description here

1 个答案:

答案 0 :(得分:0)

枚举有效,但any_or_all未保存,因为Admin::Dispatcher类的属性与attr_accessor冲突。

您可以从any_or_all列表中删除attr_accessor,但它会有效。

这似乎是因为对象上的enum方法defines a #{name}= method,被attr_accessor覆盖。