This time, the output is how to describe the foreign key in the strong parameter.
controller.rb
private
def item_params
params.require(:item).permit(:name, :description, :category, :brand, :condition, :shipping_cost, :prefecture_id, :shipping_day, :price, images_attributes: [:image]).merge(user_id: current_user.id)
end
Described using the merge method
like this.
In this case, the id of the logged-in user is saved in the parameter as user_id`.
This time the output is concise! Please refer to!
Recommended Posts