ActiveModel::ForbiddenAttributesError

ActiveModel::ForbiddenAttributesError in PurchasesController#create

ActiveModel::ForbiddenAttributesError

Extracted source (around line #9):
7
8
9
10
11
12
              
def create
@item = Item.find(params[:item_id])
Purchase.create(purchase_params)
User_private.create(user_private_params)
 
# if @purchase.save
 

Rails.root: /Users/tak/projects/furima-32036

調べてみるとストロングパラメーター関連のエラーようだ

このPurchaseモデルは他の二つのモデルのid管理をするためのもので、テーブルの中に入力して保存するパラメーターはない。

だからストロングパラメーターでpermit するものがなかったので記述しなかった。

 

params.merge(user_id: current_user.id, item_id: @item.id)


 これでエラーが起きてしまったので、色々考えた結果何もなくてもpermit の記述は必要らしく以下のようにするとエラーがなくなった。

 

params.permit().merge(user_id: current_user.id, item_id: @item.id)
 

 


 次から次へとエラーの嵐でなかなか進まない。

けど負けない!ということで引き続き頑張る。