Me aparece un error ActiveSupport::HashWithIndifferentAccess
cuando intento actualizar un formulario incrustado.ActiveSupport :: HashWithIndifferentAccess en Embedded Form Update
Aquí está el ejemplo más sencillo:
Forma:
<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 %>
Modelos:
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
controlador:
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
Este es el objeto params[:players_to_team]
en forma de s RESENTACIÓN:
¿Qué significa un error ActiveSupport::HashWithIndifferentAccess
? ¿Qué debo hacer para que este formulario actualice la entrada players_to_team
?
Editar
BT
es una columna en players_to_teams
. Si elimino el bloque field_for
, puedo guardar con éxito el campo BT
/players_to_teams
fila.
Gracias
lo que el atributo "BT" - que es el nombre correcto de un campo de la mesa players_to_teams? –
Sí. Pregunta actualizada para proporcionar más información. –
puede cambiar "<% = field.fields_for @ players_to_teams.player" por "<% = field.fields_for: player" –