Разработать регистрацию "строка не соответствует" с полем JsonB - PullRequest
0 голосов
/ 05 февраля 2019

Когда я удаляю поле: location, форма работает.Однако мне нужно получить его для хранения данных jsonb.

IndexError в 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

Схема

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

МОДЕЛЬ

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_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>

1 Ответ

0 голосов
/ 05 февраля 2019

Ошибка с

по умолчанию: "{}"

В процессе миграции.Это должно было быть

{}

Первый - строка, второй - хеш.Вы не можете присвоить ключ хешу.

...