我正在创建第一个 Rails 应用程序,昨天一切正常。我今天在我的视图上创建了关联,让玩家可以使用 has_many 和 belongs_to 拉到团队页面。现在我无法创建新播放器,因为它在 PlayersController#create 消息中不断给我一个 ActiveModel::ForbiddenAttributesError。
提取的源代码(在第 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"}
我用于创建的玩家控制器是:
def create @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
结尾