2017-02-02 14 views
0

Во время процесса регистрации у меня есть модель пользователя и модель Арендатора. Недавно я добавил сериализованный столбец модели Tenant, и я могу обновить этот столбец в порядке. Однако при создании нового Арендатора я разработал создание арендатора по вложенным параметрам, и я получаю следующую ошибку: ActiveRecord::SerializationTypeMismatch (Attribute was supposed to be a Hash, but was a String. -- "{}"): Важно отметить, что я не касаюсь этой колонки во время процесса регистрации, который я пробовал, включая столбец дезинфицирующего средства, но он делает то же самое. На схеме есть значение по умолчанию, которое равно '{}'. Ниже некоторые из кода:Неудачная регистрация с помощью модели вложенных параметров Devise имеет сериализованный столбец

create_table "tenants", force: :cascade do |t| 
    t.string "tenant_name" 
    t.string "tenant_address" 
    t.string "tenant_city" 
    t.string "tenant_zip" 
    t.string "tenant_phone" 
    t.datetime "created_at",      null: false 
    t.datetime "updated_at",      null: false 
    t.boolean "authorized" 
    t.boolean "trial" 
    t.string "plan_id" 
    t.string "plan_name" 
    t.string "braintree_id" 
    t.string "subscription_id" 
    t.jsonb "preferences",  default: "{}", null: false 
    t.string "tenant_state" 
    t.string "tenant_country" 
    t.index ["preferences"], name: "index_tenants_on_preferences", using: :gin 

конца

class Tenant < ApplicationRecord 
    has_many :users, :dependent => :delete_all 
    has_many :customers, :dependent => :delete_all 
    has_many :work_orders, :dependent => :delete_all 
    has_many :vehicles, :dependent => :delete_all 
    has_many :suppliers, :dependent => :delete_all 
end 

serialize :preferences, Hash 
store_accessor :preferences, :state_tax, :mun_tax, :welcome_sms,  :estimate_sms, :completed_sms, :disclaimer 

Вот часть моего контроллера пользователя:

class Users::RegistrationsController < Devise::RegistrationsController 
    before_action :configure_sign_up_params, only: [:create] 
    # before_action :configure_account_update_params, only: [:update] 

    # GET /resource/sign_up 
    def new 
     build_resource({}) 
     self.resource.tenant = Tenant.new 
     respond_with self.resource 
    end 

    # POST /resource 
    def create 
    super 
    if @user.save 
    @result = Braintree::Customer.create(
     :first_name => @user.name, 
     :last_name => @user.lastname, 
     :company => @user.tenant.tenant_name, 
     :email => @user.email, 
     :phone => @user.phone 
     ) 
     if @result.success? 
     @user.tenant.set_braintree_id(@result.customer.id) 
     flash[:notice] = 'Thanks you! and Welcome to Autokick.tech enjoy your free 30 days!' 
     else 
      flash[:notice] = @result.errors 
     end 
     end 
    end 

ответ

0

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

По умолчанию строки "{}" как ошибки говорит.
Измените его на default: {} без кавычек.