埋め込みフォームを更新しようとするとActiveSupport::HashWithIndifferentAccess
エラーが発生します。埋め込みフォームの更新時にActiveSupport :: HashWithIndifferentAccess
ここでは最も簡単な例は次のとおり
フォーム:
<h1>PlayersToTeams#edit</h1>
<%= form_for @players_to_teams do |field| %>
<%= field.fields_for @players_to_teams.player do |f| %>
<%= f.label :IsActive %>
<%= f.text_field :IsActive %>
<% end %>
<%= field.label :BT %>
<%= field.text_field :BT %>
<br/>
<%= field.submit "Save", class: 'btn btn-primary' %>
<% end %>
モデル:
class PlayersToTeam < ActiveRecord::Base
belongs_to :player
belongs_to :team
accepts_nested_attributes_for :player
end
class Player < ActiveRecord::Base
has_many :players_to_teams
has_many :teams, through: :players_to_teams
end
は、コントローラ:
class PlayersToTeamsController < ApplicationController
def edit
@players_to_teams=PlayersToTeam.find(params[:id])
end
def update
@players_to_teams=PlayersToTeam.find(params[:id])
respond_to do |format|
if @players_to_teams.update_attributes(params[:players_to_team])
format.html { redirect_to @players_to_teams, notice: 'Player_to_Team was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @players_to_teams.errors, status: :unprocessable_entity }
end
end
end
end
これは、フォームの時params[:players_to_team]
オブジェクトでありますubmission:
ActiveSupport::HashWithIndifferentAccess
エラーは何を意味するのでしょうか?このフォームでplayers_to_team
のエントリを更新するにはどうすればよいですか?
編集
BT
はplayers_to_teams
の列です。 field_for
ブロックを削除すると、BT
フィールド/ players_to_teams
行を正常に保存できます。
ないということである - そのフィールドの正しい名前がオンになっていますplayers_to_teamsのテーブル? –
はい。詳細を提供するために質問が更新されました。 –
"<%= field.fields_for @ players_to_teams.player"を "<%= field.fields_for:player"に変更することができます –