Обновите каждое значение jsonb - PullRequest
0 голосов
/ 01 января 2019

Я работаю с полем jsonb в моей пользовательской модели.

class User < ActiveRecord::Base
  serialize :preferences, HashSerializer
  store_accessor :preferences, :optin, :privacy
end

Предпочтения одного пользователя:

{
  "optin" => {
    "app" => true,
    "actions" => true,
    "other" => true,
  "privacy" => {
    "email" => 3,
    "profile" => 1,
    "intetests" => 1
  }
}

Как мне удается создавать формы с simple_form для редактированияпредпочтения?

Пример:

<%= simple_form_for @user, url: :update_optin do |form| %>
  <%= form.input :app, as: :boolean, label: 'App' %>
  <%= form.input :actions, as: :boolean, label: 'Actions' %>
  <%= form.input :other, as: :boolean, label: 'Other' %>
  <%= form.button :submit, 'Save' %>
<% end %>

<%= simple_form_for @user, url: :update_privacy do |form| %>
  <%= form.input :email, as: :boolean, label: 'Email' %>
  <%= form.input :profile, as: :boolean, label: 'Profile' %>
  <%= form.input :interests, as: :boolean, label: 'Interests' %>
  <%= form.button :submit, 'Save' %>
<% end %>

Было бы намного лучше, если бы вы могли сделать это только в одной форме.

Я искал по всей сетибез подсказки.

...