我尝试在表单中设置单表继承模型类型。所以我有一个属性选择菜单:类型,值是 STI 子类的名称。问题是错误日志不断打印:
警告:无法批量分配这些受保护的属性:类型
所以我在模型中添加了“attr_accessible:type”:
class ContentItem < ActiveRecord::Base
# needed so we can set/update :type in mass
attr_accessible :position, :description, :type, :url, :youtube_id, :start_time, :end_time
validates_presence_of :position
belongs_to :chapter
has_many :user_content_items
end
不会改变任何东西,在控制器中调用 .update_attributes() 之后 ContentItem 仍然有 :type=nil 。知道如何从表单中批量更新 :type 吗?