2017-02-02 7 views
0

サインアッププロセス中に私はユーザモデルとテナントモデルを持っています。最近、シリアル化された列をテナントモデルに追加しました。この列をうまく更新できます。しかし、新しいテナントを作成するときは、入れ子になったパラメータでテナントを作成するように工夫しています。次のエラーが発生します。 ActiveRecord::SerializationTypeMismatch (Attribute was supposed to be a Hash, but was a String. -- "{}"):登録プロセス中にその列に触れないことに注意してください。それは同じです。スキーマにはデフォルト値 '{}'があります。コードの一部を下回る:Signed Signup with 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: {}に変更してください。

関連する問題