2016-06-14 159 views
2

我想用戶信息加入到2代表的表關聯是協會類型不匹配

Distributor Table: 

    class Distributor < ApplicationRecord 

      has_one :authentication, dependent: :destroy 
    end 

Authentication Table 

    class Authentication < ApplicationRecord 

     belongs_to :distributor 
     belongs_to :user 

     validates :email,presence: true 



     before_save :create_remember_token 

     private 
     def create_remember_token 
      self.remember_token = SecureRandom.urlsafe_base64 
     end 

     end 

Authentication table details 


    Authentication(id: integer, email: string, password: string, created_at: datetime, updated_at: datetime, admin: boolean, remember_token: string, user_id: integer, mail_confirmation: boolean, distributor: boolean, distributor_id: integer) 

控制器創建

def create 
     @distributor = Distributor.new(distributor_params) 
     if @distributor.save 
     params[:distributor][:distributor_id] = @distributor.id 
     params[:distributor][:password] = "Default" 
     params[:distributor][:distributor] = "true" 
     @authe_distributor = Authentication.new(authen_distributor_params) 
     if @authe_distributor.save 
       redirect_to @distributor 
     else 
       render 'new' 
     end 
     else 
     render 'new' 
     end 

    end 

每當我嘗試添加我得到這個細節錯誤..任何人告訴我我做錯了什麼..

enter image description here

回答

1

您的Authentication模型具有同名的列和關聯:分銷商。這是有問題的,因爲儘管您試圖將名爲distributionr的列設置爲"true",但試圖將關聯設置爲導致異常的值。

重命名列或關聯,以便不再發生此衝突,問題應該消失。

+0

非常感謝你:) – Pranavadurai