设计注册“字符串不匹配”与JsonB场

问题描述 投票:0回答:1

当我删除了:位置字段,形式的作品。不过,我需要它来存储数据jsonb。

IndexError in RegistrationsController#create

字符串不匹配

 Extracted source (around line #151):

          if value != read(object, attribute, key)
            object.public_send :"#{attribute}_will_change!"
            object.public_send(attribute)[key] = value
          end
        end

RegistrationsController

class RegistrationsController < Devise::RegistrationsController
  protected


  private 

  def sign_up_params
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :location)
  end

  def account_update_params
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :location)
  end

end

Schema

t.jsonb "interests", default: "{}", null: false

MODEL

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  # These fields are within the interests jsonb field
  store_accessor :interests, :location

end

FORM

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= bootstrap_devise_error_messages! %>

  <div class="form-group">
    <%= f.label :email %>
    <%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control' %>
  </div>

  <div class="form-group">
    <%= f.label :location %>
    <%= f.text_field :location, class: 'form-control' %>
  </div>
ruby-on-rails devise ruby-on-rails-5 jsonb
1个回答
0
投票

错误与

默认: “{}”

在迁移。它需要的是

{}

前者是一个字符串,后者的哈希值。你不能键指定给一个哈希值。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.