关联类型不匹配

Association Type mismatch

我正在尝试将用户详细信息添加到 2 tables table 关联是

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

每当我尝试添加详细信息时,我都会收到此错误.. 谁能告诉我我做错了什么..

您的 Authentication 模型有一个列和一个同名的关联:分销商。这是有问题的,因为尽管您尝试将名为 distributor 的列设置为 "true" rails,但最终尝试将关联设置为导致异常的值。

重命名列或关联,这样您就不会再遇到此冲突,问题就会消失。