如何解决JSONB:store_model gem修改过帐数据的内容
我正在使用StoreModel gem将我的JSON支持的DB列setting
包装为类似ActiveModel的类。这是我的模型简化模型
class Entity < ApplicationRecord
attribute :settings,Setting.to_type # settings is a jsonb datatype in the database
end
class Setting
include StoreModel::Model
attribute :setting1,:boolean
attribute :setting2,:boolean
attribute :setting3,:boolean
end
对于表单,我具有以下内容
<%= form_for @entity do |f| %>
<%= fields_for :settings,@entity.settings do |ff| %>
<%= ff.check_Box :setting1 %>
<%= ff.check_Box :setting2 %>
<% end %
<% end %>
对于现有记录,这将覆盖我的实体模型的settings属性中的所有值,因此将set3设置为null(不通过表单/参数传递)!如何提交值以保留现有值,并只修改我提交的值。
解决方法
之前在GitHub issue中已进行了讨论,TLDR不可能即用即用,但是有workaround。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。