【问题标题】:JSONB: store_model gem. Modify content on posting dataJSONB:store_model 宝石。修改发布数据的内容
【发布时间】:2021-01-26 17:52:56
【问题描述】:

我正在使用 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 属性中的所有值,因此它将 setting3 设置为 no null (不是由表单/参数传递的)!如何提交值以保留现有值并仅修改我提交的值。

【问题讨论】:

    标签: ruby-on-rails model store jsonb


    【解决方案1】:

    之前在 GitHub issue 中讨论过,TLDR 不可能开箱即用,但有一个 workaround

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-15
      • 2016-01-09
      • 1970-01-01
      • 2010-11-17
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多