製品が製品コントローラーに保存されたら、トランザクションログを作成しようとしています。何らかの理由で、トランザクションログを保存しようとするとエラーが発生します。製品は正常に保存されています。
コード:
def create 
  @product = Product.new(params[:product])                                                                                                      
  respond_to do |format|                                                                                                                        
  if @product.save
    ProductTransaction.create(
      :product_id => @product.id,                                                                                                             
      :user_id => current_user.id,                                                                                                            
      :message => "Product created"                                                                                                           
    )                                                                                                                                         
    format.html { 
      redirect_to product_path(@product.id), 
      :flash => { :success => "Product was successfully created." } 
    }                      
    else
      format.html { render action: "new" }                                                                                                      
    end                                                                                                                                         
  end                                                                                                                                           
end              
エラー:
PGError: ERROR:  column "product_id" is of type integer but expression is of type character varying at character 117
HINT:  You will need to rewrite or cast the expression.
: INSERT INTO "product_transactions" ("created_at", "message", "product_id", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"
上記のエラーがわかりません。テーブルを再確認しましたが、product_idは整数です。また、数値をハードコーディングして、保存できるかどうかを確認しました。それはうまくいきませんでした。次に、create関数からすべてのパラメーターを削除しましたが、それでも同じエラーが発生しました。テーブルを最初から再作成しても同じ結果になりました。ProductTransactionには検証要件はありません。私は何が間違っているのですか?
コード(削除されたパラメーター):
def create 
  @product = Product.new(params[:product])                                                                                                      
  respond_to do |format|                                                                                                                        
  if @product.save
    ProductTransaction.create()                                                                                                                                                                                     
    format.html { 
      redirect_to product_path(@product.id), 
      :flash => { :success => "Product was successfully created." } 
    }                      
    else
      format.html { render action: "new" }                                                                                                      
    end                                                                                                                                         
  end                                                                                                                                           
end              
製品スキーマ:
Product(id:integer, name:string, etc.)
製品トランザクションスキーマ:
ProductTransaction(id:integer, user_id:integer, product_id:integer, message:integer)