Introducing devise to link users and posts (It is not necessary to devise, but current_user must be defined by @current_user)
**
by referring to here@gear = Gear.new(
**gear_params,
user_id: current_user.id
)
⇒ Sinked by the mysterious error hash key" "is not a Symbol
@gear = Gear.new(
category: params[:category],
name: params[:name],
maker: params[:maker],
price: params[:price],
memo: params[:memo],
user_id: current_user.id
)
For some reason it is rolled back and not saved in the database. .. ʻActiveRecord :: RecordInvalid (validation failed: enter User` (unsolved)
def create
@gear = Gear.new(
gear_params
)
@gear.user_id = current_user.id
.
.
.
end
Because I stumbled upon saving a post from the model associated with the user. As a memorandum
gear_params writes:
private
def gear_params
params.require(:gear).permit(:category, :name, :maker, :price, :memo)
end
Recommended Posts