当我尝试更新嵌入式表单时,出现ActiveSupport::HashWithIndifferentAccess
错误。ActiveSupport :: HashWithIndifferentAccess on Embedded Form Update
下面是最简单的例子:
形式:
<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
行。
谢谢
是什么属性“BT” - 是一个字段的正确名称上表players_to_teams? – 2012-04-05 02:09:14
是的。问题更新提供更多信息。 – 2012-04-05 02:12:23
你能否将“<%= field.fields_for @ players_to_teams.player”更改为“<%= field.fields_for:player” – 2012-04-05 03:05:39