我正在使用用户模型中的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 %>
如果我们可以仅用一种形式进行操作,那就更好了。
我一直在网上寻找线索。