Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveSupport::HashWithIndifferentAccess on Embedded Form Update
    primarykey
    data
    text
    <p>I'm getting an <code>ActiveSupport::HashWithIndifferentAccess</code> error when I try to update an embedded form.</p> <p>Here's the simplest example:</p> <p>Form:</p> <pre><code>&lt;h1&gt;PlayersToTeams#edit&lt;/h1&gt; &lt;%= form_for @players_to_teams do |field| %&gt; &lt;%= field.fields_for @players_to_teams.player do |f| %&gt; &lt;%= f.label :IsActive %&gt; &lt;%= f.text_field :IsActive %&gt; &lt;% end %&gt; &lt;%= field.label :BT %&gt; &lt;%= field.text_field :BT %&gt; &lt;br/&gt; &lt;%= field.submit "Save", class: 'btn btn-primary' %&gt; &lt;% end %&gt; </code></pre> <p>Models:</p> <pre><code>class PlayersToTeam &lt; ActiveRecord::Base belongs_to :player belongs_to :team accepts_nested_attributes_for :player end class Player &lt; ActiveRecord::Base has_many :players_to_teams has_many :teams, through: :players_to_teams end </code></pre> <p>Controller:</p> <pre><code>class PlayersToTeamsController &lt; 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 </code></pre> <p>This is the <code>params[:players_to_team]</code> object upon form submission:</p> <p><img src="https://i.stack.imgur.com/lx5QK.png" alt=":players_to_team "> </p> <p>What does an <code>ActiveSupport::HashWithIndifferentAccess</code> error mean? What do I need to do to have this form update the <code>players_to_team</code> entry?</p> <p><strong>Edit</strong></p> <p><code>BT</code> is a column in <code>players_to_teams</code>. If I remove teh <code>field_for</code> block, I can successfully save the <code>BT</code> field/the <code>players_to_teams</code> row.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload