我正在創建第一個rails應用程序,並且昨天一切正常。我今天創建了關於我的觀點的關聯,讓玩家可以通過has_many和belongs_to進入團隊頁面。現在我無法創建一個新玩家,因爲它一直在PlayerController#create message中給我一個ActiveModel :: ForbiddenAttributesError。PlayersController中的ActiveModel :: ForbiddenAttributesError#create
提取的源(左右線#27):
def create
@player = Player.create(params[:player])
respond_to do |format|
if @player.save
參數:
{"utf8"=>"✓",
"authenticity_token"=>"uw5w2sOgNF6y3+Jv6kvTj3X/dV2+PAVo2/OyHinIirY=",
"player"=>{"first_name"=>"test",
"last_name"=>"",
"address_1"=>"",
"address_2"=>"",
"city"=>"",
"state"=>"",
"zip"=>"",
"phone_number"=>"",
"email"=>"",
"birthday"=>"",
"position"=>"",
"bio"=>"",
"team"=>"",
"team_id"=>"1",
"number"=>""},
"commit"=>"Create Player"}
我的球員控制器創建是:
高清創建 @player = Player.new( player_params)
respond_to do |format|
if @player.save
format.html { redirect_to @player, notice: 'Player was successfully created.' }
format.json { render action: 'show', status: :created, location: @player }
else
format.html { render action: 'new' }
format.json { render json: @player.errors, status: :unprocessable_entity }
end
end
末
嗨本傑明...謝謝你的迴應。這似乎並沒有這樣做。我已經將player_params設置爲params.require。 –
看到我的回答波紋管 – Benj